typeorm 0.3.28-dev.925dee0 → 0.3.28-dev.b639d33
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/browser/driver/mongodb/MongoConnectionOptions.d.ts +16 -0
- package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/browser/driver/mongodb/MongoDriver.js +5 -0
- package/browser/driver/mongodb/MongoDriver.js.map +1 -1
- package/browser/driver/mongodb/typings.d.ts +5 -0
- package/browser/driver/mongodb/typings.js.map +1 -1
- package/browser/driver/postgres/PostgresDriver.d.ts +1 -2
- package/browser/driver/postgres/PostgresDriver.js +1 -2
- package/browser/driver/postgres/PostgresDriver.js.map +1 -1
- package/browser/find-options/FindOptionsUtils.d.ts +0 -161
- package/browser/find-options/FindOptionsUtils.js +0 -161
- package/browser/find-options/FindOptionsUtils.js.map +1 -1
- package/commands/InitCommand.js +23 -16
- package/commands/InitCommand.js.map +1 -1
- package/driver/mongodb/MongoConnectionOptions.d.ts +16 -0
- package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/driver/mongodb/MongoDriver.js +5 -0
- package/driver/mongodb/MongoDriver.js.map +1 -1
- package/driver/mongodb/typings.d.ts +5 -0
- package/driver/mongodb/typings.js.map +1 -1
- package/driver/postgres/PostgresDriver.d.ts +1 -2
- package/driver/postgres/PostgresDriver.js +1 -2
- package/driver/postgres/PostgresDriver.js.map +1 -1
- package/find-options/FindOptionsUtils.d.ts +0 -161
- package/find-options/FindOptionsUtils.js +0 -161
- package/find-options/FindOptionsUtils.js.map +1 -1
- package/package.json +1 -1
|
@@ -20,167 +20,6 @@ export declare class FindOptionsUtils {
|
|
|
20
20
|
* Checks if given object is really instance of FindOptions interface.
|
|
21
21
|
*/
|
|
22
22
|
static extractFindManyOptionsAlias(object: any): string | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* Applies give find many options to the given query builder.
|
|
25
|
-
|
|
26
|
-
static applyFindManyOptionsOrConditionsToQueryBuilder<T>(qb: SelectQueryBuilder<T>, options: FindManyOptions<T>|Partial<T>|undefined): SelectQueryBuilder<T> {
|
|
27
|
-
if (this.isFindManyOptions(options))
|
|
28
|
-
return this.applyOptionsToQueryBuilder(qb, options);
|
|
29
|
-
|
|
30
|
-
if (options)
|
|
31
|
-
return qb.where(options);
|
|
32
|
-
|
|
33
|
-
return qb;
|
|
34
|
-
}*/
|
|
35
|
-
/**
|
|
36
|
-
* Applies give find options to the given query builder.
|
|
37
|
-
|
|
38
|
-
static applyOptionsToQueryBuilder<T>(qb: SelectQueryBuilder<T>, options: FindOneOptions<T>|FindManyOptions<T>|undefined): SelectQueryBuilder<T> {
|
|
39
|
-
|
|
40
|
-
// if options are not set then simply return query builder. This is made for simplicity of usage.
|
|
41
|
-
if (!options || (!this.isFindOneOptions(options) && !this.isFindManyOptions(options)))
|
|
42
|
-
return qb;
|
|
43
|
-
|
|
44
|
-
if (options.transaction === true) {
|
|
45
|
-
qb.expressionMap.useTransaction = true;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!qb.expressionMap.mainAlias || !qb.expressionMap.mainAlias.hasMetadata)
|
|
49
|
-
return qb;
|
|
50
|
-
|
|
51
|
-
const metadata = qb.expressionMap.mainAlias!.metadata;
|
|
52
|
-
|
|
53
|
-
// apply all options from FindOptions
|
|
54
|
-
if (options.comment) {
|
|
55
|
-
qb.comment(options.comment);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (options.withDeleted) {
|
|
59
|
-
qb.withDeleted();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (options.select) {
|
|
63
|
-
qb.select([]);
|
|
64
|
-
options.select.forEach(select => {
|
|
65
|
-
if (!metadata.hasColumnWithPropertyPath(`${select}`))
|
|
66
|
-
throw new TypeORMError(`${select} column was not found in the ${metadata.name} entity.`);
|
|
67
|
-
|
|
68
|
-
const columns = metadata.findColumnsWithPropertyPath(`${select}`);
|
|
69
|
-
|
|
70
|
-
for (const column of columns) {
|
|
71
|
-
qb.addSelect(qb.alias + "." + column.propertyPath);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (options.relations) {
|
|
77
|
-
// Copy because `applyRelationsRecursively` modifies it
|
|
78
|
-
const allRelations = [...options.relations];
|
|
79
|
-
this.applyRelationsRecursively(qb, allRelations, qb.expressionMap.mainAlias!.name, qb.expressionMap.mainAlias!.metadata, "");
|
|
80
|
-
// recursive removes found relations from allRelations array
|
|
81
|
-
// if there are relations left in this array it means those relations were not found in the entity structure
|
|
82
|
-
// so, we give an exception about not found relations
|
|
83
|
-
if (allRelations.length > 0)
|
|
84
|
-
throw new FindRelationsNotFoundError(allRelations);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (options.join) {
|
|
88
|
-
if (options.join.leftJoin)
|
|
89
|
-
Object.keys(options.join.leftJoin).forEach(key => {
|
|
90
|
-
qb.leftJoin(options.join!.leftJoin![key], key);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
if (options.join.innerJoin)
|
|
94
|
-
Object.keys(options.join.innerJoin).forEach(key => {
|
|
95
|
-
qb.innerJoin(options.join!.innerJoin![key], key);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
if (options.join.leftJoinAndSelect)
|
|
99
|
-
Object.keys(options.join.leftJoinAndSelect).forEach(key => {
|
|
100
|
-
qb.leftJoinAndSelect(options.join!.leftJoinAndSelect![key], key);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
if (options.join.innerJoinAndSelect)
|
|
104
|
-
Object.keys(options.join.innerJoinAndSelect).forEach(key => {
|
|
105
|
-
qb.innerJoinAndSelect(options.join!.innerJoinAndSelect![key], key);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (options.cache) {
|
|
110
|
-
if (options.cache instanceof Object) {
|
|
111
|
-
const cache = options.cache as { id: any, milliseconds: number };
|
|
112
|
-
qb.cache(cache.id, cache.milliseconds);
|
|
113
|
-
} else {
|
|
114
|
-
qb.cache(options.cache);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (options.lock) {
|
|
119
|
-
if (options.lock.mode === "optimistic") {
|
|
120
|
-
qb.setLock(options.lock.mode, options.lock.version);
|
|
121
|
-
} else if (
|
|
122
|
-
options.lock.mode === "pessimistic_read" ||
|
|
123
|
-
options.lock.mode === "pessimistic_write" ||
|
|
124
|
-
options.lock.mode === "dirty_read" ||
|
|
125
|
-
options.lock.mode === "pessimistic_partial_write" ||
|
|
126
|
-
options.lock.mode === "pessimistic_write_or_fail" ||
|
|
127
|
-
options.lock.mode === "for_no_key_update" ||
|
|
128
|
-
options.lock.mode === "for_key_share"
|
|
129
|
-
) {
|
|
130
|
-
const tableNames = options.lock.tables ? options.lock.tables.map((table) => {
|
|
131
|
-
const tableAlias = qb.expressionMap.aliases.find((alias) => {
|
|
132
|
-
return alias.metadata.tableNameWithoutPrefix === table;
|
|
133
|
-
});
|
|
134
|
-
if (!tableAlias) {
|
|
135
|
-
throw new TypeORMError(`"${table}" is not part of this query`);
|
|
136
|
-
}
|
|
137
|
-
return qb.escape(tableAlias.name);
|
|
138
|
-
}) : undefined;
|
|
139
|
-
qb.setLock(options.lock.mode, undefined, tableNames);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (options.loadRelationIds === true) {
|
|
144
|
-
qb.loadAllRelationIds();
|
|
145
|
-
|
|
146
|
-
} else if (options.loadRelationIds instanceof Object) {
|
|
147
|
-
qb.loadAllRelationIds(options.loadRelationIds as any);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (options.where)
|
|
151
|
-
qb.where(options.where);
|
|
152
|
-
|
|
153
|
-
if ((options as FindManyOptions<T>).skip)
|
|
154
|
-
qb.skip((options as FindManyOptions<T>).skip!);
|
|
155
|
-
|
|
156
|
-
if ((options as FindManyOptions<T>).take)
|
|
157
|
-
qb.take((options as FindManyOptions<T>).take!);
|
|
158
|
-
|
|
159
|
-
if (options.order)
|
|
160
|
-
Object.keys(options.order).forEach(key => {
|
|
161
|
-
const order = ((options as FindOneOptions<T>).order as any)[key as any];
|
|
162
|
-
|
|
163
|
-
if (!metadata.findColumnWithPropertyPath(key))
|
|
164
|
-
throw new Error(`${key} column was not found in the ${metadata.name} entity.`);
|
|
165
|
-
|
|
166
|
-
switch (order) {
|
|
167
|
-
case 1:
|
|
168
|
-
qb.addOrderBy(qb.alias + "." + key, "ASC");
|
|
169
|
-
break;
|
|
170
|
-
case -1:
|
|
171
|
-
qb.addOrderBy(qb.alias + "." + key, "DESC");
|
|
172
|
-
break;
|
|
173
|
-
case "ASC":
|
|
174
|
-
qb.addOrderBy(qb.alias + "." + key, "ASC");
|
|
175
|
-
break;
|
|
176
|
-
case "DESC":
|
|
177
|
-
qb.addOrderBy(qb.alias + "." + key, "DESC");
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
return qb;
|
|
183
|
-
}*/
|
|
184
23
|
static applyOptionsToTreeQueryBuilder<T extends ObjectLiteral>(qb: SelectQueryBuilder<T>, options?: FindTreeOptions): SelectQueryBuilder<T>;
|
|
185
24
|
/**
|
|
186
25
|
* Adds joins for all relations and sub-relations of the given relations provided in the find options.
|
|
@@ -58,167 +58,6 @@ export class FindOptionsUtils {
|
|
|
58
58
|
return object.join.alias;
|
|
59
59
|
return undefined;
|
|
60
60
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Applies give find many options to the given query builder.
|
|
63
|
-
|
|
64
|
-
static applyFindManyOptionsOrConditionsToQueryBuilder<T>(qb: SelectQueryBuilder<T>, options: FindManyOptions<T>|Partial<T>|undefined): SelectQueryBuilder<T> {
|
|
65
|
-
if (this.isFindManyOptions(options))
|
|
66
|
-
return this.applyOptionsToQueryBuilder(qb, options);
|
|
67
|
-
|
|
68
|
-
if (options)
|
|
69
|
-
return qb.where(options);
|
|
70
|
-
|
|
71
|
-
return qb;
|
|
72
|
-
}*/
|
|
73
|
-
/**
|
|
74
|
-
* Applies give find options to the given query builder.
|
|
75
|
-
|
|
76
|
-
static applyOptionsToQueryBuilder<T>(qb: SelectQueryBuilder<T>, options: FindOneOptions<T>|FindManyOptions<T>|undefined): SelectQueryBuilder<T> {
|
|
77
|
-
|
|
78
|
-
// if options are not set then simply return query builder. This is made for simplicity of usage.
|
|
79
|
-
if (!options || (!this.isFindOneOptions(options) && !this.isFindManyOptions(options)))
|
|
80
|
-
return qb;
|
|
81
|
-
|
|
82
|
-
if (options.transaction === true) {
|
|
83
|
-
qb.expressionMap.useTransaction = true;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (!qb.expressionMap.mainAlias || !qb.expressionMap.mainAlias.hasMetadata)
|
|
87
|
-
return qb;
|
|
88
|
-
|
|
89
|
-
const metadata = qb.expressionMap.mainAlias!.metadata;
|
|
90
|
-
|
|
91
|
-
// apply all options from FindOptions
|
|
92
|
-
if (options.comment) {
|
|
93
|
-
qb.comment(options.comment);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (options.withDeleted) {
|
|
97
|
-
qb.withDeleted();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (options.select) {
|
|
101
|
-
qb.select([]);
|
|
102
|
-
options.select.forEach(select => {
|
|
103
|
-
if (!metadata.hasColumnWithPropertyPath(`${select}`))
|
|
104
|
-
throw new TypeORMError(`${select} column was not found in the ${metadata.name} entity.`);
|
|
105
|
-
|
|
106
|
-
const columns = metadata.findColumnsWithPropertyPath(`${select}`);
|
|
107
|
-
|
|
108
|
-
for (const column of columns) {
|
|
109
|
-
qb.addSelect(qb.alias + "." + column.propertyPath);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (options.relations) {
|
|
115
|
-
// Copy because `applyRelationsRecursively` modifies it
|
|
116
|
-
const allRelations = [...options.relations];
|
|
117
|
-
this.applyRelationsRecursively(qb, allRelations, qb.expressionMap.mainAlias!.name, qb.expressionMap.mainAlias!.metadata, "");
|
|
118
|
-
// recursive removes found relations from allRelations array
|
|
119
|
-
// if there are relations left in this array it means those relations were not found in the entity structure
|
|
120
|
-
// so, we give an exception about not found relations
|
|
121
|
-
if (allRelations.length > 0)
|
|
122
|
-
throw new FindRelationsNotFoundError(allRelations);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (options.join) {
|
|
126
|
-
if (options.join.leftJoin)
|
|
127
|
-
Object.keys(options.join.leftJoin).forEach(key => {
|
|
128
|
-
qb.leftJoin(options.join!.leftJoin![key], key);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
if (options.join.innerJoin)
|
|
132
|
-
Object.keys(options.join.innerJoin).forEach(key => {
|
|
133
|
-
qb.innerJoin(options.join!.innerJoin![key], key);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
if (options.join.leftJoinAndSelect)
|
|
137
|
-
Object.keys(options.join.leftJoinAndSelect).forEach(key => {
|
|
138
|
-
qb.leftJoinAndSelect(options.join!.leftJoinAndSelect![key], key);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
if (options.join.innerJoinAndSelect)
|
|
142
|
-
Object.keys(options.join.innerJoinAndSelect).forEach(key => {
|
|
143
|
-
qb.innerJoinAndSelect(options.join!.innerJoinAndSelect![key], key);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (options.cache) {
|
|
148
|
-
if (options.cache instanceof Object) {
|
|
149
|
-
const cache = options.cache as { id: any, milliseconds: number };
|
|
150
|
-
qb.cache(cache.id, cache.milliseconds);
|
|
151
|
-
} else {
|
|
152
|
-
qb.cache(options.cache);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (options.lock) {
|
|
157
|
-
if (options.lock.mode === "optimistic") {
|
|
158
|
-
qb.setLock(options.lock.mode, options.lock.version);
|
|
159
|
-
} else if (
|
|
160
|
-
options.lock.mode === "pessimistic_read" ||
|
|
161
|
-
options.lock.mode === "pessimistic_write" ||
|
|
162
|
-
options.lock.mode === "dirty_read" ||
|
|
163
|
-
options.lock.mode === "pessimistic_partial_write" ||
|
|
164
|
-
options.lock.mode === "pessimistic_write_or_fail" ||
|
|
165
|
-
options.lock.mode === "for_no_key_update" ||
|
|
166
|
-
options.lock.mode === "for_key_share"
|
|
167
|
-
) {
|
|
168
|
-
const tableNames = options.lock.tables ? options.lock.tables.map((table) => {
|
|
169
|
-
const tableAlias = qb.expressionMap.aliases.find((alias) => {
|
|
170
|
-
return alias.metadata.tableNameWithoutPrefix === table;
|
|
171
|
-
});
|
|
172
|
-
if (!tableAlias) {
|
|
173
|
-
throw new TypeORMError(`"${table}" is not part of this query`);
|
|
174
|
-
}
|
|
175
|
-
return qb.escape(tableAlias.name);
|
|
176
|
-
}) : undefined;
|
|
177
|
-
qb.setLock(options.lock.mode, undefined, tableNames);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (options.loadRelationIds === true) {
|
|
182
|
-
qb.loadAllRelationIds();
|
|
183
|
-
|
|
184
|
-
} else if (options.loadRelationIds instanceof Object) {
|
|
185
|
-
qb.loadAllRelationIds(options.loadRelationIds as any);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (options.where)
|
|
189
|
-
qb.where(options.where);
|
|
190
|
-
|
|
191
|
-
if ((options as FindManyOptions<T>).skip)
|
|
192
|
-
qb.skip((options as FindManyOptions<T>).skip!);
|
|
193
|
-
|
|
194
|
-
if ((options as FindManyOptions<T>).take)
|
|
195
|
-
qb.take((options as FindManyOptions<T>).take!);
|
|
196
|
-
|
|
197
|
-
if (options.order)
|
|
198
|
-
Object.keys(options.order).forEach(key => {
|
|
199
|
-
const order = ((options as FindOneOptions<T>).order as any)[key as any];
|
|
200
|
-
|
|
201
|
-
if (!metadata.findColumnWithPropertyPath(key))
|
|
202
|
-
throw new Error(`${key} column was not found in the ${metadata.name} entity.`);
|
|
203
|
-
|
|
204
|
-
switch (order) {
|
|
205
|
-
case 1:
|
|
206
|
-
qb.addOrderBy(qb.alias + "." + key, "ASC");
|
|
207
|
-
break;
|
|
208
|
-
case -1:
|
|
209
|
-
qb.addOrderBy(qb.alias + "." + key, "DESC");
|
|
210
|
-
break;
|
|
211
|
-
case "ASC":
|
|
212
|
-
qb.addOrderBy(qb.alias + "." + key, "ASC");
|
|
213
|
-
break;
|
|
214
|
-
case "DESC":
|
|
215
|
-
qb.addOrderBy(qb.alias + "." + key, "DESC");
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
return qb;
|
|
221
|
-
}*/
|
|
222
61
|
static applyOptionsToTreeQueryBuilder(qb, options) {
|
|
223
62
|
if (options?.relations) {
|
|
224
63
|
// Copy because `applyRelationsRecursively` modifies it
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/find-options/FindOptionsUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAA;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAInD,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAA;AAEtD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACzB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,gBAAgB,CACnB,GAAQ;QAER,MAAM,eAAe,GAA2B,GAAG,CAAA;QACnD,OAAO,CACH,eAAe;YACf,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC;gBAClC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC;gBACxC,OAAO,eAAe,CAAC,MAAM,KAAK,QAAQ;gBAC1C,OAAO,eAAe,CAAC,SAAS,KAAK,QAAQ;gBAC7C,OAAO,eAAe,CAAC,KAAK,KAAK,QAAQ;gBACzC,+CAA+C;gBA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M,IAAI,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;gBAC5C,IACI,MAAM,CAAC,SAAS,KAAK,SAAS;oBAC9B,MAAM,CAAC,OAAO,KAAK,SAAS;oBAC5B,MAAM,CAAC,SAAS,KAAK,aAAa,EACpC,CAAC;oBACC,SAAQ;gBACZ,CAAC;gBACD,SAAS,GAAG,KAAK,CAAA;gBACjB,MAAK;YACT,CAAC;YAED,IAAI,SAAS,EAAE,CAAC;gBACZ,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAA;YAC/B,CAAC;YAED,uCAAuC;YACvC,IAAI,CAAC,kBAAkB,CACnB,EAAE,EACF,aAAa,EACb,QAAQ,CAAC,qBAAqB,CACjC,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ","file":"FindOptionsUtils.js","sourcesContent":["import { FindManyOptions } from \"./FindManyOptions\"\nimport { FindOneOptions } from \"./FindOneOptions\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { FindRelationsNotFoundError } from \"../error\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { FindTreeOptions } from \"./FindTreeOptions\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { RelationMetadata } from \"../metadata/RelationMetadata\"\nimport { EntityPropertyNotFoundError } from \"../error\"\n\n/**\n * Utilities to work with FindOptions.\n */\nexport class FindOptionsUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if given object is really instance of FindOneOptions interface.\n */\n static isFindOneOptions<Entity = any>(\n obj: any,\n ): obj is FindOneOptions<Entity> {\n const possibleOptions: FindOneOptions<Entity> = obj\n return (\n possibleOptions &&\n (Array.isArray(possibleOptions.select) ||\n Array.isArray(possibleOptions.relations) ||\n typeof possibleOptions.select === \"object\" ||\n typeof possibleOptions.relations === \"object\" ||\n typeof possibleOptions.where === \"object\" ||\n // typeof possibleOptions.where === \"string\" ||\n typeof possibleOptions.join === \"object\" ||\n typeof possibleOptions.order === \"object\" ||\n typeof possibleOptions.cache === \"object\" ||\n typeof possibleOptions.cache === \"boolean\" ||\n typeof possibleOptions.cache === \"number\" ||\n typeof possibleOptions.comment === \"string\" ||\n typeof possibleOptions.lock === \"object\" ||\n typeof possibleOptions.loadRelationIds === \"object\" ||\n typeof possibleOptions.loadRelationIds === \"boolean\" ||\n typeof possibleOptions.loadEagerRelations === \"boolean\" ||\n typeof possibleOptions.withDeleted === \"boolean\" ||\n typeof possibleOptions.relationLoadStrategy === \"string\" ||\n typeof possibleOptions.transaction === \"boolean\")\n )\n }\n\n /**\n * Checks if given object is really instance of FindManyOptions interface.\n */\n static isFindManyOptions<Entity = any>(\n obj: any,\n ): obj is FindManyOptions<Entity> {\n const possibleOptions: FindManyOptions<Entity> = obj\n return (\n possibleOptions &&\n (this.isFindOneOptions(possibleOptions) ||\n typeof (possibleOptions as FindManyOptions<any>).skip ===\n \"number\" ||\n typeof (possibleOptions as FindManyOptions<any>).take ===\n \"number\" ||\n typeof (possibleOptions as FindManyOptions<any>).skip ===\n \"string\" ||\n typeof (possibleOptions as FindManyOptions<any>).take ===\n \"string\")\n )\n }\n\n /**\n * Checks if given object is really instance of FindOptions interface.\n */\n static extractFindManyOptionsAlias(object: any): string | undefined {\n if (this.isFindManyOptions(object) && object.join)\n return object.join.alias\n\n return undefined\n }\n\n /**\n * Applies give find many options to the given query builder.\n\n static applyFindManyOptionsOrConditionsToQueryBuilder<T>(qb: SelectQueryBuilder<T>, options: FindManyOptions<T>|Partial<T>|undefined): SelectQueryBuilder<T> {\n if (this.isFindManyOptions(options))\n return this.applyOptionsToQueryBuilder(qb, options);\n\n if (options)\n return qb.where(options);\n\n return qb;\n }*/\n\n /**\n * Applies give find options to the given query builder.\n\n static applyOptionsToQueryBuilder<T>(qb: SelectQueryBuilder<T>, options: FindOneOptions<T>|FindManyOptions<T>|undefined): SelectQueryBuilder<T> {\n\n // if options are not set then simply return query builder. This is made for simplicity of usage.\n if (!options || (!this.isFindOneOptions(options) && !this.isFindManyOptions(options)))\n return qb;\n\n if (options.transaction === true) {\n qb.expressionMap.useTransaction = true;\n }\n\n if (!qb.expressionMap.mainAlias || !qb.expressionMap.mainAlias.hasMetadata)\n return qb;\n\n const metadata = qb.expressionMap.mainAlias!.metadata;\n\n // apply all options from FindOptions\n if (options.comment) {\n qb.comment(options.comment);\n }\n\n if (options.withDeleted) {\n qb.withDeleted();\n }\n\n if (options.select) {\n qb.select([]);\n options.select.forEach(select => {\n if (!metadata.hasColumnWithPropertyPath(`${select}`))\n throw new TypeORMError(`${select} column was not found in the ${metadata.name} entity.`);\n\n const columns = metadata.findColumnsWithPropertyPath(`${select}`);\n\n for (const column of columns) {\n qb.addSelect(qb.alias + \".\" + column.propertyPath);\n }\n });\n }\n\n if (options.relations) {\n // Copy because `applyRelationsRecursively` modifies it\n const allRelations = [...options.relations];\n this.applyRelationsRecursively(qb, allRelations, qb.expressionMap.mainAlias!.name, qb.expressionMap.mainAlias!.metadata, \"\");\n // recursive removes found relations from allRelations array\n // if there are relations left in this array it means those relations were not found in the entity structure\n // so, we give an exception about not found relations\n if (allRelations.length > 0)\n throw new FindRelationsNotFoundError(allRelations);\n }\n\n if (options.join) {\n if (options.join.leftJoin)\n Object.keys(options.join.leftJoin).forEach(key => {\n qb.leftJoin(options.join!.leftJoin![key], key);\n });\n\n if (options.join.innerJoin)\n Object.keys(options.join.innerJoin).forEach(key => {\n qb.innerJoin(options.join!.innerJoin![key], key);\n });\n\n if (options.join.leftJoinAndSelect)\n Object.keys(options.join.leftJoinAndSelect).forEach(key => {\n qb.leftJoinAndSelect(options.join!.leftJoinAndSelect![key], key);\n });\n\n if (options.join.innerJoinAndSelect)\n Object.keys(options.join.innerJoinAndSelect).forEach(key => {\n qb.innerJoinAndSelect(options.join!.innerJoinAndSelect![key], key);\n });\n }\n\n if (options.cache) {\n if (options.cache instanceof Object) {\n const cache = options.cache as { id: any, milliseconds: number };\n qb.cache(cache.id, cache.milliseconds);\n } else {\n qb.cache(options.cache);\n }\n }\n\n if (options.lock) {\n if (options.lock.mode === \"optimistic\") {\n qb.setLock(options.lock.mode, options.lock.version);\n } else if (\n options.lock.mode === \"pessimistic_read\" ||\n options.lock.mode === \"pessimistic_write\" ||\n options.lock.mode === \"dirty_read\" ||\n options.lock.mode === \"pessimistic_partial_write\" ||\n options.lock.mode === \"pessimistic_write_or_fail\" ||\n options.lock.mode === \"for_no_key_update\" ||\n options.lock.mode === \"for_key_share\"\n ) {\n const tableNames = options.lock.tables ? options.lock.tables.map((table) => {\n const tableAlias = qb.expressionMap.aliases.find((alias) => {\n return alias.metadata.tableNameWithoutPrefix === table;\n });\n if (!tableAlias) {\n throw new TypeORMError(`\"${table}\" is not part of this query`);\n }\n return qb.escape(tableAlias.name);\n }) : undefined;\n qb.setLock(options.lock.mode, undefined, tableNames);\n }\n }\n\n if (options.loadRelationIds === true) {\n qb.loadAllRelationIds();\n\n } else if (options.loadRelationIds instanceof Object) {\n qb.loadAllRelationIds(options.loadRelationIds as any);\n }\n\n if (options.where)\n qb.where(options.where);\n\n if ((options as FindManyOptions<T>).skip)\n qb.skip((options as FindManyOptions<T>).skip!);\n\n if ((options as FindManyOptions<T>).take)\n qb.take((options as FindManyOptions<T>).take!);\n\n if (options.order)\n Object.keys(options.order).forEach(key => {\n const order = ((options as FindOneOptions<T>).order as any)[key as any];\n\n if (!metadata.findColumnWithPropertyPath(key))\n throw new Error(`${key} column was not found in the ${metadata.name} entity.`);\n\n switch (order) {\n case 1:\n qb.addOrderBy(qb.alias + \".\" + key, \"ASC\");\n break;\n case -1:\n qb.addOrderBy(qb.alias + \".\" + key, \"DESC\");\n break;\n case \"ASC\":\n qb.addOrderBy(qb.alias + \".\" + key, \"ASC\");\n break;\n case \"DESC\":\n qb.addOrderBy(qb.alias + \".\" + key, \"DESC\");\n break;\n }\n });\n\n return qb;\n }*/\n\n static applyOptionsToTreeQueryBuilder<T extends ObjectLiteral>(\n qb: SelectQueryBuilder<T>,\n options?: FindTreeOptions,\n ): SelectQueryBuilder<T> {\n if (options?.relations) {\n // Copy because `applyRelationsRecursively` modifies it\n const allRelations = [...options.relations]\n\n FindOptionsUtils.applyRelationsRecursively(\n qb,\n allRelations,\n qb.expressionMap.mainAlias!.name,\n qb.expressionMap.mainAlias!.metadata,\n \"\",\n )\n\n // recursive removes found relations from allRelations array\n // if there are relations left in this array it means those relations were not found in the entity structure\n // so, we give an exception about not found relations\n if (allRelations.length > 0)\n throw new FindRelationsNotFoundError(allRelations)\n }\n\n return qb\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Adds joins for all relations and sub-relations of the given relations provided in the find options.\n */\n public static applyRelationsRecursively(\n qb: SelectQueryBuilder<any>,\n allRelations: string[],\n alias: string,\n metadata: EntityMetadata,\n prefix: string,\n ): void {\n // find all relations that match given prefix\n let matchedBaseRelations: RelationMetadata[] = []\n if (prefix) {\n const regexp = new RegExp(\"^\" + prefix.replace(\".\", \"\\\\.\") + \"\\\\.\")\n matchedBaseRelations = allRelations\n .filter((relation) => relation.match(regexp))\n .map((relation) =>\n metadata.findRelationWithPropertyPath(\n relation.replace(regexp, \"\"),\n ),\n )\n .filter((entity) => entity) as RelationMetadata[]\n } else {\n matchedBaseRelations = allRelations\n .map((relation) =>\n metadata.findRelationWithPropertyPath(relation),\n )\n .filter((entity) => entity) as RelationMetadata[]\n }\n\n // go through all matched relations and add join for them\n matchedBaseRelations.forEach((relation) => {\n // generate a relation alias\n const relationAlias: string = DriverUtils.buildAlias(\n qb.connection.driver,\n { joiner: \"__\" },\n alias,\n relation.propertyPath,\n )\n\n // add a join for the found relation\n const selection = alias + \".\" + relation.propertyPath\n if (qb.expressionMap.relationLoadStrategy === \"query\") {\n qb.concatRelationMetadata(relation)\n } else {\n qb.leftJoinAndSelect(selection, relationAlias)\n }\n\n // remove added relations from the allRelations array, this is needed to find all not found relations at the end\n allRelations.splice(\n allRelations.indexOf(\n prefix\n ? prefix + \".\" + relation.propertyPath\n : relation.propertyPath,\n ),\n 1,\n )\n\n // try to find sub-relations\n let relationMetadata: EntityMetadata | undefined\n let relationName: string | undefined\n\n if (qb.expressionMap.relationLoadStrategy === \"query\") {\n relationMetadata = relation.inverseEntityMetadata\n relationName = relationAlias\n } else {\n const join = qb.expressionMap.joinAttributes.find(\n (join) => join.entityOrProperty === selection,\n )\n relationMetadata = join!.metadata!\n relationName = join!.alias.name\n }\n\n if (!relationName || !relationMetadata) {\n throw new EntityPropertyNotFoundError(\n relation.propertyPath,\n metadata,\n )\n }\n\n this.applyRelationsRecursively(\n qb,\n allRelations,\n relationName,\n relationMetadata,\n prefix\n ? prefix + \".\" + relation.propertyPath\n : relation.propertyPath,\n )\n\n // join the eager relations of the found relation\n // Only supported for \"join\" relationLoadStrategy\n if (qb.expressionMap.relationLoadStrategy === \"join\") {\n const relMetadata = metadata.relations.find(\n (metadata) =>\n metadata.propertyName === relation.propertyPath,\n )\n if (relMetadata) {\n this.joinEagerRelations(\n qb,\n relationAlias,\n relMetadata.inverseEntityMetadata,\n )\n }\n }\n })\n }\n\n public static joinEagerRelations(\n qb: SelectQueryBuilder<any>,\n alias: string,\n metadata: EntityMetadata,\n ) {\n metadata.eagerRelations.forEach((relation) => {\n // generate a relation alias\n let relationAlias: string = DriverUtils.buildAlias(\n qb.connection.driver,\n { joiner: \"__\" },\n alias,\n relation.propertyName,\n )\n\n // add a join for the relation\n // Checking whether the relation wasn't joined yet.\n let addJoin = true\n // TODO: Review this validation\n for (const join of qb.expressionMap.joinAttributes) {\n if (\n join.condition !== undefined ||\n join.mapToProperty !== undefined ||\n join.isMappingMany !== undefined ||\n join.direction !== \"LEFT\" ||\n join.entityOrProperty !==\n `${alias}.${relation.propertyPath}`\n ) {\n continue\n }\n addJoin = false\n relationAlias = join.alias.name\n break\n }\n\n const joinAlreadyAdded = Boolean(\n qb.expressionMap.joinAttributes.find(\n (joinAttribute) =>\n joinAttribute.alias.name === relationAlias,\n ),\n )\n\n if (addJoin && !joinAlreadyAdded) {\n qb.leftJoin(alias + \".\" + relation.propertyPath, relationAlias)\n }\n\n // Checking whether the relation wasn't selected yet.\n // This check shall be after the join check to detect relationAlias.\n let addSelect = true\n for (const select of qb.expressionMap.selects) {\n if (\n select.aliasName !== undefined ||\n select.virtual !== undefined ||\n select.selection !== relationAlias\n ) {\n continue\n }\n addSelect = false\n break\n }\n\n if (addSelect) {\n qb.addSelect(relationAlias)\n }\n\n // (recursive) join the eager relations\n this.joinEagerRelations(\n qb,\n relationAlias,\n relation.inverseEntityMetadata,\n )\n })\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/find-options/FindOptionsUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAA;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAInD,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAA;AAEtD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACzB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,gBAAgB,CACnB,GAAQ;QAER,MAAM,eAAe,GAA2B,GAAG,CAAA;QACnD,OAAO,CACH,eAAe;YACf,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC;gBAClC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC;gBACxC,OAAO,eAAe,CAAC,MAAM,KAAK,QAAQ;gBAC1C,OAAO,eAAe,CAAC,SAAS,KAAK,QAAQ;gBAC7C,OAAO,eAAe,CAAC,KAAK,KAAK,QAAQ;gBACzC,+CAA+C;gBAC/C,OAAO,eAAe,CAAC,IAAI,KAAK,QAAQ;gBACxC,OAAO,eAAe,CAAC,KAAK,KAAK,QAAQ;gBACzC,OAAO,eAAe,CAAC,KAAK,K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C,CAAA;YAC/B,CAAC;YAED,uCAAuC;YACvC,IAAI,CAAC,kBAAkB,CACnB,EAAE,EACF,aAAa,EACb,QAAQ,CAAC,qBAAqB,CACjC,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ","file":"FindOptionsUtils.js","sourcesContent":["import { FindManyOptions } from \"./FindManyOptions\"\nimport { FindOneOptions } from \"./FindOneOptions\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { FindRelationsNotFoundError } from \"../error\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { FindTreeOptions } from \"./FindTreeOptions\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { RelationMetadata } from \"../metadata/RelationMetadata\"\nimport { EntityPropertyNotFoundError } from \"../error\"\n\n/**\n * Utilities to work with FindOptions.\n */\nexport class FindOptionsUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if given object is really instance of FindOneOptions interface.\n */\n static isFindOneOptions<Entity = any>(\n obj: any,\n ): obj is FindOneOptions<Entity> {\n const possibleOptions: FindOneOptions<Entity> = obj\n return (\n possibleOptions &&\n (Array.isArray(possibleOptions.select) ||\n Array.isArray(possibleOptions.relations) ||\n typeof possibleOptions.select === \"object\" ||\n typeof possibleOptions.relations === \"object\" ||\n typeof possibleOptions.where === \"object\" ||\n // typeof possibleOptions.where === \"string\" ||\n typeof possibleOptions.join === \"object\" ||\n typeof possibleOptions.order === \"object\" ||\n typeof possibleOptions.cache === \"object\" ||\n typeof possibleOptions.cache === \"boolean\" ||\n typeof possibleOptions.cache === \"number\" ||\n typeof possibleOptions.comment === \"string\" ||\n typeof possibleOptions.lock === \"object\" ||\n typeof possibleOptions.loadRelationIds === \"object\" ||\n typeof possibleOptions.loadRelationIds === \"boolean\" ||\n typeof possibleOptions.loadEagerRelations === \"boolean\" ||\n typeof possibleOptions.withDeleted === \"boolean\" ||\n typeof possibleOptions.relationLoadStrategy === \"string\" ||\n typeof possibleOptions.transaction === \"boolean\")\n )\n }\n\n /**\n * Checks if given object is really instance of FindManyOptions interface.\n */\n static isFindManyOptions<Entity = any>(\n obj: any,\n ): obj is FindManyOptions<Entity> {\n const possibleOptions: FindManyOptions<Entity> = obj\n return (\n possibleOptions &&\n (this.isFindOneOptions(possibleOptions) ||\n typeof (possibleOptions as FindManyOptions<any>).skip ===\n \"number\" ||\n typeof (possibleOptions as FindManyOptions<any>).take ===\n \"number\" ||\n typeof (possibleOptions as FindManyOptions<any>).skip ===\n \"string\" ||\n typeof (possibleOptions as FindManyOptions<any>).take ===\n \"string\")\n )\n }\n\n /**\n * Checks if given object is really instance of FindOptions interface.\n */\n static extractFindManyOptionsAlias(object: any): string | undefined {\n if (this.isFindManyOptions(object) && object.join)\n return object.join.alias\n\n return undefined\n }\n\n static applyOptionsToTreeQueryBuilder<T extends ObjectLiteral>(\n qb: SelectQueryBuilder<T>,\n options?: FindTreeOptions,\n ): SelectQueryBuilder<T> {\n if (options?.relations) {\n // Copy because `applyRelationsRecursively` modifies it\n const allRelations = [...options.relations]\n\n FindOptionsUtils.applyRelationsRecursively(\n qb,\n allRelations,\n qb.expressionMap.mainAlias!.name,\n qb.expressionMap.mainAlias!.metadata,\n \"\",\n )\n\n // recursive removes found relations from allRelations array\n // if there are relations left in this array it means those relations were not found in the entity structure\n // so, we give an exception about not found relations\n if (allRelations.length > 0)\n throw new FindRelationsNotFoundError(allRelations)\n }\n\n return qb\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Adds joins for all relations and sub-relations of the given relations provided in the find options.\n */\n public static applyRelationsRecursively(\n qb: SelectQueryBuilder<any>,\n allRelations: string[],\n alias: string,\n metadata: EntityMetadata,\n prefix: string,\n ): void {\n // find all relations that match given prefix\n let matchedBaseRelations: RelationMetadata[] = []\n if (prefix) {\n const regexp = new RegExp(\"^\" + prefix.replace(\".\", \"\\\\.\") + \"\\\\.\")\n matchedBaseRelations = allRelations\n .filter((relation) => relation.match(regexp))\n .map((relation) =>\n metadata.findRelationWithPropertyPath(\n relation.replace(regexp, \"\"),\n ),\n )\n .filter((entity) => entity) as RelationMetadata[]\n } else {\n matchedBaseRelations = allRelations\n .map((relation) =>\n metadata.findRelationWithPropertyPath(relation),\n )\n .filter((entity) => entity) as RelationMetadata[]\n }\n\n // go through all matched relations and add join for them\n matchedBaseRelations.forEach((relation) => {\n // generate a relation alias\n const relationAlias: string = DriverUtils.buildAlias(\n qb.connection.driver,\n { joiner: \"__\" },\n alias,\n relation.propertyPath,\n )\n\n // add a join for the found relation\n const selection = alias + \".\" + relation.propertyPath\n if (qb.expressionMap.relationLoadStrategy === \"query\") {\n qb.concatRelationMetadata(relation)\n } else {\n qb.leftJoinAndSelect(selection, relationAlias)\n }\n\n // remove added relations from the allRelations array, this is needed to find all not found relations at the end\n allRelations.splice(\n allRelations.indexOf(\n prefix\n ? prefix + \".\" + relation.propertyPath\n : relation.propertyPath,\n ),\n 1,\n )\n\n // try to find sub-relations\n let relationMetadata: EntityMetadata | undefined\n let relationName: string | undefined\n\n if (qb.expressionMap.relationLoadStrategy === \"query\") {\n relationMetadata = relation.inverseEntityMetadata\n relationName = relationAlias\n } else {\n const join = qb.expressionMap.joinAttributes.find(\n (join) => join.entityOrProperty === selection,\n )\n relationMetadata = join!.metadata!\n relationName = join!.alias.name\n }\n\n if (!relationName || !relationMetadata) {\n throw new EntityPropertyNotFoundError(\n relation.propertyPath,\n metadata,\n )\n }\n\n this.applyRelationsRecursively(\n qb,\n allRelations,\n relationName,\n relationMetadata,\n prefix\n ? prefix + \".\" + relation.propertyPath\n : relation.propertyPath,\n )\n\n // join the eager relations of the found relation\n // Only supported for \"join\" relationLoadStrategy\n if (qb.expressionMap.relationLoadStrategy === \"join\") {\n const relMetadata = metadata.relations.find(\n (metadata) =>\n metadata.propertyName === relation.propertyPath,\n )\n if (relMetadata) {\n this.joinEagerRelations(\n qb,\n relationAlias,\n relMetadata.inverseEntityMetadata,\n )\n }\n }\n })\n }\n\n public static joinEagerRelations(\n qb: SelectQueryBuilder<any>,\n alias: string,\n metadata: EntityMetadata,\n ) {\n metadata.eagerRelations.forEach((relation) => {\n // generate a relation alias\n let relationAlias: string = DriverUtils.buildAlias(\n qb.connection.driver,\n { joiner: \"__\" },\n alias,\n relation.propertyName,\n )\n\n // add a join for the relation\n // Checking whether the relation wasn't joined yet.\n let addJoin = true\n // TODO: Review this validation\n for (const join of qb.expressionMap.joinAttributes) {\n if (\n join.condition !== undefined ||\n join.mapToProperty !== undefined ||\n join.isMappingMany !== undefined ||\n join.direction !== \"LEFT\" ||\n join.entityOrProperty !==\n `${alias}.${relation.propertyPath}`\n ) {\n continue\n }\n addJoin = false\n relationAlias = join.alias.name\n break\n }\n\n const joinAlreadyAdded = Boolean(\n qb.expressionMap.joinAttributes.find(\n (joinAttribute) =>\n joinAttribute.alias.name === relationAlias,\n ),\n )\n\n if (addJoin && !joinAlreadyAdded) {\n qb.leftJoin(alias + \".\" + relation.propertyPath, relationAlias)\n }\n\n // Checking whether the relation wasn't selected yet.\n // This check shall be after the join check to detect relationAlias.\n let addSelect = true\n for (const select of qb.expressionMap.selects) {\n if (\n select.aliasName !== undefined ||\n select.virtual !== undefined ||\n select.selection !== relationAlias\n ) {\n continue\n }\n addSelect = false\n break\n }\n\n if (addSelect) {\n qb.addSelect(relationAlias)\n }\n\n // (recursive) join the eager relations\n this.joinEagerRelations(\n qb,\n relationAlias,\n relation.inverseEntityMetadata,\n )\n })\n }\n}\n"],"sourceRoot":".."}
|
package/commands/InitCommand.js
CHANGED
|
@@ -8,6 +8,7 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
8
8
|
const error_1 = require("../error");
|
|
9
9
|
const PlatformTools_1 = require("../platform/PlatformTools");
|
|
10
10
|
const CommandUtils_1 = require("./CommandUtils");
|
|
11
|
+
const package_json_1 = tslib_1.__importDefault(require("../package.json"));
|
|
11
12
|
/**
|
|
12
13
|
* Generates a new project with TypeORM.
|
|
13
14
|
*/
|
|
@@ -529,7 +530,7 @@ AppDataSource.initialize().then(async () => {
|
|
|
529
530
|
return `services:
|
|
530
531
|
|
|
531
532
|
mongodb:
|
|
532
|
-
image: "mongo:8
|
|
533
|
+
image: "mongo:8"
|
|
533
534
|
container_name: "typeorm-mongodb"
|
|
534
535
|
ports:
|
|
535
536
|
- "27017:27017"
|
|
@@ -578,46 +579,52 @@ Steps to run this project:
|
|
|
578
579
|
if (!packageJson.devDependencies)
|
|
579
580
|
packageJson.devDependencies = {};
|
|
580
581
|
packageJson.devDependencies = {
|
|
581
|
-
"@types/node":
|
|
582
|
-
"ts-node":
|
|
583
|
-
typescript:
|
|
582
|
+
"@types/node": package_json_1.default.devDependencies["@types/node"],
|
|
583
|
+
"ts-node": package_json_1.default.devDependencies["ts-node"],
|
|
584
|
+
typescript: package_json_1.default.devDependencies.typescript,
|
|
584
585
|
...packageJson.devDependencies,
|
|
585
586
|
};
|
|
586
587
|
if (!packageJson.dependencies)
|
|
587
588
|
packageJson.dependencies = {};
|
|
588
589
|
packageJson.dependencies = {
|
|
589
590
|
...packageJson.dependencies,
|
|
590
|
-
"reflect-metadata":
|
|
591
|
-
typeorm:
|
|
592
|
-
? require("../package.json").version // install version from package.json if present
|
|
593
|
-
: require("../package.json").installFrom, // else use custom source
|
|
591
|
+
"reflect-metadata": package_json_1.default.dependencies["reflect-metadata"],
|
|
592
|
+
typeorm: package_json_1.default.version,
|
|
594
593
|
};
|
|
595
594
|
switch (database) {
|
|
596
595
|
case "mysql":
|
|
597
596
|
case "mariadb":
|
|
598
|
-
packageJson.dependencies["mysql2"] =
|
|
597
|
+
packageJson.dependencies["mysql2"] =
|
|
598
|
+
package_json_1.default.devDependencies.mysql2;
|
|
599
599
|
break;
|
|
600
600
|
case "postgres":
|
|
601
601
|
case "cockroachdb":
|
|
602
|
-
packageJson.dependencies["pg"] =
|
|
602
|
+
packageJson.dependencies["pg"] =
|
|
603
|
+
package_json_1.default.devDependencies.pg;
|
|
603
604
|
break;
|
|
604
605
|
case "sqlite":
|
|
605
|
-
packageJson.dependencies["sqlite3"] =
|
|
606
|
+
packageJson.dependencies["sqlite3"] =
|
|
607
|
+
package_json_1.default.devDependencies.sqlite3;
|
|
606
608
|
break;
|
|
607
609
|
case "better-sqlite3":
|
|
608
|
-
packageJson.dependencies["better-sqlite3"] =
|
|
610
|
+
packageJson.dependencies["better-sqlite3"] =
|
|
611
|
+
package_json_1.default.devDependencies["better-sqlite3"];
|
|
609
612
|
break;
|
|
610
613
|
case "oracle":
|
|
611
|
-
packageJson.dependencies["oracledb"] =
|
|
614
|
+
packageJson.dependencies["oracledb"] =
|
|
615
|
+
package_json_1.default.devDependencies.oracledb;
|
|
612
616
|
break;
|
|
613
617
|
case "mssql":
|
|
614
|
-
packageJson.dependencies["mssql"] =
|
|
618
|
+
packageJson.dependencies["mssql"] =
|
|
619
|
+
package_json_1.default.devDependencies.mssql;
|
|
615
620
|
break;
|
|
616
621
|
case "mongodb":
|
|
617
|
-
packageJson.dependencies["mongodb"] =
|
|
622
|
+
packageJson.dependencies["mongodb"] =
|
|
623
|
+
package_json_1.default.devDependencies.mongodb;
|
|
618
624
|
break;
|
|
619
625
|
case "spanner":
|
|
620
|
-
packageJson.dependencies["@google-cloud/spanner"] =
|
|
626
|
+
packageJson.dependencies["@google-cloud/spanner"] =
|
|
627
|
+
package_json_1.default.devDependencies["@google-cloud/spanner"];
|
|
621
628
|
break;
|
|
622
629
|
}
|
|
623
630
|
if (express) {
|