@goatlab/fluent 0.6.6 → 0.6.7
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Repository } from 'typeorm';
|
|
2
|
-
import {
|
|
3
|
-
import type { Filter, DaoOutput, BaseDataElement, PaginatedData, Paginator, Sure } from '../
|
|
2
|
+
import { BaseConnector, FluentConnectorInterface } from '../BaseConnector';
|
|
3
|
+
import type { Filter, DaoOutput, BaseDataElement, PaginatedData, Paginator, Sure } from '../types';
|
|
4
4
|
export declare class GoatRepository<T> extends Repository<T> {
|
|
5
5
|
}
|
|
6
6
|
export declare const getRelations: (typeOrmRepo: any) => {
|
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeOrmConnector = exports.getRelations = exports.GoatRepository = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const mongodb_1 = require("mongodb");
|
|
6
|
+
const js_utils_1 = require("@goatlab/js-utils");
|
|
7
|
+
const loadRelations_1 = require("../loadRelations");
|
|
8
|
+
const BaseConnector_1 = require("../BaseConnector");
|
|
9
|
+
const generatorDatasource_1 = require("../generatorDatasource");
|
|
10
|
+
const outputKeys_1 = require("../outputKeys");
|
|
11
|
+
class GoatRepository extends typeorm_1.Repository {
|
|
12
|
+
}
|
|
13
|
+
exports.GoatRepository = GoatRepository;
|
|
14
|
+
const getRelations = typeOrmRepo => {
|
|
15
|
+
const relations = {};
|
|
16
|
+
for (const relation of typeOrmRepo.metadata.relations) {
|
|
17
|
+
relations[relation.inverseEntityMetadata.givenTableName.toLowerCase()] = {
|
|
18
|
+
isOneToMany: relation.isOneToMany,
|
|
19
|
+
isManyToOne: relation.isManyToOne,
|
|
20
|
+
isManyToMany: relation.isManyToMany,
|
|
21
|
+
inverseSidePropertyPath: relation.inverseSidePropertyPath,
|
|
22
|
+
propertyPath: relation.propertyName,
|
|
23
|
+
entityName: relation.inverseEntityMetadata.name,
|
|
24
|
+
tableName: relation.inverseEntityMetadata.tableName,
|
|
25
|
+
targetClass: relation.inverseEntityMetadata.target,
|
|
26
|
+
joinColumns: relation.joinColumns,
|
|
27
|
+
inverseJoinColumns: relation.inverseJoinColumns
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
relations
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.getRelations = getRelations;
|
|
35
|
+
class TypeOrmConnector extends BaseConnector_1.BaseConnector {
|
|
36
|
+
constructor(entity, relationQuery, connectionName) {
|
|
37
|
+
super();
|
|
38
|
+
this.connectionName = connectionName;
|
|
39
|
+
if (!generatorDatasource_1.modelGeneratorDataSource.isInitialized) {
|
|
40
|
+
throw new Error('Fluent model generator data source is not initialized');
|
|
41
|
+
}
|
|
42
|
+
this.repository = generatorDatasource_1.modelGeneratorDataSource.getRepository(entity);
|
|
43
|
+
this.relationQuery = relationQuery;
|
|
44
|
+
const { relations } = (0, exports.getRelations)(this.repository);
|
|
45
|
+
this.modelRelations = relations;
|
|
46
|
+
this.outputKeys = (0, outputKeys_1.getOutputKeys)(this.repository) || [];
|
|
47
|
+
this.isMongoDB =
|
|
48
|
+
this.repository.metadata.connection.driver.options.type === 'mongodb';
|
|
49
|
+
}
|
|
50
|
+
async get() {
|
|
51
|
+
const query = this.getGeneratedQuery();
|
|
52
|
+
const result = await this.repository.find(query);
|
|
53
|
+
let data = this.jsApplySelect(result);
|
|
54
|
+
data = await (0, loadRelations_1.loadRelations)({
|
|
55
|
+
data,
|
|
56
|
+
relations: this.relations,
|
|
57
|
+
modelRelations: this.modelRelations,
|
|
58
|
+
connectionName: this.connectionName,
|
|
59
|
+
provider: 'typeorm',
|
|
60
|
+
self: this
|
|
61
|
+
});
|
|
62
|
+
this.reset();
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
async getPaginated() {
|
|
66
|
+
const response = await this.get();
|
|
67
|
+
const results = {
|
|
68
|
+
current_page: response[0].meta.currentPage,
|
|
69
|
+
data: response[0].data,
|
|
70
|
+
first_page_url: response[0].meta.firstPageUrl,
|
|
71
|
+
next_page_url: response[0].meta.nextPageUrl,
|
|
72
|
+
path: response[0].meta.path,
|
|
73
|
+
per_page: response[0].meta.itemsPerPage,
|
|
74
|
+
prev_page_url: response[0].meta.previousPageUrl,
|
|
75
|
+
total: response[0].meta.totalItemCount
|
|
76
|
+
};
|
|
77
|
+
if (results && results.data && this.selectArray.length > 0) {
|
|
78
|
+
results.data = this.jsApplySelect(results.data);
|
|
79
|
+
return results;
|
|
80
|
+
}
|
|
81
|
+
return results;
|
|
82
|
+
}
|
|
83
|
+
async all() {
|
|
84
|
+
return this.get();
|
|
85
|
+
}
|
|
86
|
+
async find(filter = {}) {
|
|
87
|
+
const stringFilter = filter;
|
|
88
|
+
let parsedFilter = {};
|
|
89
|
+
try {
|
|
90
|
+
parsedFilter = JSON.parse(stringFilter);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
parsedFilter = {};
|
|
94
|
+
}
|
|
95
|
+
this.selectArray = (parsedFilter && parsedFilter.fields) || [];
|
|
96
|
+
this.whereArray =
|
|
97
|
+
(parsedFilter && parsedFilter.where && parsedFilter.where.and) || [];
|
|
98
|
+
this.orWhereArray =
|
|
99
|
+
(parsedFilter && parsedFilter.where && parsedFilter.where.or) || [];
|
|
100
|
+
this.limit((parsedFilter && (parsedFilter.limit || parsedFilter.take)) || 100);
|
|
101
|
+
this.offset((parsedFilter && (parsedFilter.offset || parsedFilter.skip)) || 0);
|
|
102
|
+
if (parsedFilter && parsedFilter.order) {
|
|
103
|
+
const orderB = [
|
|
104
|
+
parsedFilter.order.field,
|
|
105
|
+
parsedFilter.order.asc ? 'asc' : 'desc',
|
|
106
|
+
parsedFilter.order.type || 'string'
|
|
107
|
+
];
|
|
108
|
+
this.chainReference.push({ method: 'orderBy', orderB });
|
|
109
|
+
this.orderByArray = orderB;
|
|
110
|
+
}
|
|
111
|
+
return this.get();
|
|
112
|
+
}
|
|
113
|
+
async paginate(paginator) {
|
|
114
|
+
if (!paginator) {
|
|
115
|
+
throw new Error('Paginator cannot be empty');
|
|
116
|
+
}
|
|
117
|
+
this.paginator = paginator;
|
|
118
|
+
const response = await this.getPaginated();
|
|
119
|
+
return response;
|
|
120
|
+
}
|
|
121
|
+
raw() {
|
|
122
|
+
return this.repository;
|
|
123
|
+
}
|
|
124
|
+
async insert(data) {
|
|
125
|
+
const datum = await this.repository.save(data);
|
|
126
|
+
const result = this.jsApplySelect([datum]);
|
|
127
|
+
this.reset();
|
|
128
|
+
return result[0];
|
|
129
|
+
}
|
|
130
|
+
async insertMany(data) {
|
|
131
|
+
const inserted = await this.repository.save(data, {
|
|
132
|
+
chunk: data.length / 300
|
|
133
|
+
});
|
|
134
|
+
this.reset();
|
|
135
|
+
const result = this.jsApplySelect(inserted);
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
async updateById(id, data) {
|
|
139
|
+
const parsedId = this.isMongoDB
|
|
140
|
+
? new mongodb_1.ObjectId(id)
|
|
141
|
+
: id;
|
|
142
|
+
const dataToInsert = this.outputKeys.includes('updated')
|
|
143
|
+
? {
|
|
144
|
+
...data,
|
|
145
|
+
...{ updated: new Date() }
|
|
146
|
+
}
|
|
147
|
+
: data;
|
|
148
|
+
const updated = await this.repository.update(id, dataToInsert);
|
|
149
|
+
const dbResult = await this.repository.findBy({
|
|
150
|
+
id: (0, typeorm_1.In)([parsedId])
|
|
151
|
+
});
|
|
152
|
+
const result = this.jsApplySelect(dbResult);
|
|
153
|
+
this.reset();
|
|
154
|
+
return result[0];
|
|
155
|
+
}
|
|
156
|
+
async replaceById(id, data) {
|
|
157
|
+
const parsedId = this.isMongoDB
|
|
158
|
+
? new mongodb_1.ObjectId(id)
|
|
159
|
+
: id;
|
|
160
|
+
const value = await this.repository.findOneOrFail({
|
|
161
|
+
where: { id: parsedId }
|
|
162
|
+
});
|
|
163
|
+
const flatValue = js_utils_1.Objects.flatten(JSON.parse(JSON.stringify(value)));
|
|
164
|
+
Object.keys(flatValue).forEach(key => {
|
|
165
|
+
flatValue[key] = null;
|
|
166
|
+
});
|
|
167
|
+
const nullObject = js_utils_1.Objects.nest(flatValue);
|
|
168
|
+
const newValue = { ...nullObject, ...data };
|
|
169
|
+
delete newValue._id;
|
|
170
|
+
delete newValue.id;
|
|
171
|
+
delete newValue.created;
|
|
172
|
+
delete newValue.updated;
|
|
173
|
+
const dataToInsert = this.outputKeys.includes('updated')
|
|
174
|
+
? {
|
|
175
|
+
...data,
|
|
176
|
+
...{ updated: new Date() }
|
|
177
|
+
}
|
|
178
|
+
: data;
|
|
179
|
+
await this.repository.update(id, dataToInsert);
|
|
180
|
+
const val = await this.repository.findOneOrFail({
|
|
181
|
+
where: {
|
|
182
|
+
id: parsedId
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const returnValue = this.jsApplySelect([val]);
|
|
186
|
+
this.reset();
|
|
187
|
+
return returnValue[0];
|
|
188
|
+
}
|
|
189
|
+
async clear({ sure }) {
|
|
190
|
+
if (!sure || sure !== true) {
|
|
191
|
+
throw new Error('Clear() method will delete everything!, you must set the "sure" parameter "clear({sure:true})" to continue');
|
|
192
|
+
}
|
|
193
|
+
return;
|
|
194
|
+
const data = await this.repository.clear();
|
|
195
|
+
this.reset();
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
async deleteById(id) {
|
|
199
|
+
const parsedId = this.isMongoDB
|
|
200
|
+
? new mongodb_1.ObjectId(id)
|
|
201
|
+
: id;
|
|
202
|
+
const removed = this.repository.delete(parsedId);
|
|
203
|
+
this.reset();
|
|
204
|
+
return id;
|
|
205
|
+
}
|
|
206
|
+
async findById(id) {
|
|
207
|
+
const parsedId = this.isMongoDB
|
|
208
|
+
? new mongodb_1.ObjectId(id)
|
|
209
|
+
: id;
|
|
210
|
+
const data = await this.repository.findBy({
|
|
211
|
+
id: (0, typeorm_1.In)([parsedId])
|
|
212
|
+
});
|
|
213
|
+
const result = this.jsApplySelect(data);
|
|
214
|
+
this.reset();
|
|
215
|
+
return result[0];
|
|
216
|
+
}
|
|
217
|
+
getPage() {
|
|
218
|
+
const page = 'page=';
|
|
219
|
+
if (this.paginator && this.paginator.page) {
|
|
220
|
+
return `${page + this.paginator.page}&`;
|
|
221
|
+
}
|
|
222
|
+
return '';
|
|
223
|
+
}
|
|
224
|
+
getPaginatorLimit(filter) {
|
|
225
|
+
if (this.paginator && this.paginator.perPage) {
|
|
226
|
+
return { ...filter, limit: this.paginator.perPage };
|
|
227
|
+
}
|
|
228
|
+
return filter;
|
|
229
|
+
}
|
|
230
|
+
getPopulate() {
|
|
231
|
+
const populate = [];
|
|
232
|
+
this.populateArray.forEach(relation => {
|
|
233
|
+
if (typeof relation === 'string') {
|
|
234
|
+
populate.push({ relation });
|
|
235
|
+
}
|
|
236
|
+
else if (Array.isArray(relation)) {
|
|
237
|
+
relation.forEach(nestedRelation => {
|
|
238
|
+
if (typeof nestedRelation === 'string') {
|
|
239
|
+
populate.push({ relation: nestedRelation });
|
|
240
|
+
}
|
|
241
|
+
else if (typeof nestedRelation === 'object') {
|
|
242
|
+
populate.push(nestedRelation);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
else if (typeof relation === 'object') {
|
|
247
|
+
populate.push(relation);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
return populate;
|
|
251
|
+
}
|
|
252
|
+
getGeneratedQuery() {
|
|
253
|
+
let filter = {};
|
|
254
|
+
filter = this.isMongoDB
|
|
255
|
+
? this.getMongoFilters(filter)
|
|
256
|
+
: this.getFilters(filter);
|
|
257
|
+
filter = this.getLimit(filter);
|
|
258
|
+
filter = this.getSkip(filter);
|
|
259
|
+
filter = this.getSelect(filter);
|
|
260
|
+
filter = this.getOrderBy(filter);
|
|
261
|
+
filter = this.getPaginatorLimit(filter);
|
|
262
|
+
const page = this.getPage();
|
|
263
|
+
const populate = this.getPopulate();
|
|
264
|
+
if (this.rawQuery) {
|
|
265
|
+
filter.relations = populate || this.rawQuery.populate;
|
|
266
|
+
filter.take = filter.take || this.rawQuery.limit;
|
|
267
|
+
filter.skip = filter.skip || this.rawQuery.skip;
|
|
268
|
+
filter.order = filter.order || this.rawQuery.order;
|
|
269
|
+
filter.select = { ...filter.select, ...this.rawQuery.fields };
|
|
270
|
+
filter.where = { ...this.rawQuery.where };
|
|
271
|
+
}
|
|
272
|
+
return filter;
|
|
273
|
+
}
|
|
274
|
+
getFilters(filters) {
|
|
275
|
+
const andFilters = this.whereArray;
|
|
276
|
+
const orFilters = this.orWhereArray;
|
|
277
|
+
if (this.relationQuery && this.relationQuery.data) {
|
|
278
|
+
const ids = this.relationQuery.data.map(d => d.id);
|
|
279
|
+
andFilters.push([
|
|
280
|
+
this.relationQuery.relation.inverseSidePropertyPath,
|
|
281
|
+
'in',
|
|
282
|
+
ids
|
|
283
|
+
]);
|
|
284
|
+
}
|
|
285
|
+
if (!andFilters || andFilters.length === 0) {
|
|
286
|
+
return filters;
|
|
287
|
+
}
|
|
288
|
+
const Filters = { where: [{}] };
|
|
289
|
+
andFilters.forEach(condition => {
|
|
290
|
+
const element = condition[0];
|
|
291
|
+
const operator = condition[1];
|
|
292
|
+
const value = condition[2];
|
|
293
|
+
switch (operator) {
|
|
294
|
+
case '=':
|
|
295
|
+
Filters.where[0] = js_utils_1.Objects.nest({
|
|
296
|
+
...Filters.where[0],
|
|
297
|
+
...{ [element]: (0, typeorm_1.Equal)(value) }
|
|
298
|
+
});
|
|
299
|
+
break;
|
|
300
|
+
case '!=':
|
|
301
|
+
Filters.where[0] = js_utils_1.Objects.nest({
|
|
302
|
+
...Filters.where[0],
|
|
303
|
+
...{ [element]: (0, typeorm_1.Not)((0, typeorm_1.Equal)(value)) }
|
|
304
|
+
});
|
|
305
|
+
break;
|
|
306
|
+
case '>':
|
|
307
|
+
Filters.where[0] = js_utils_1.Objects.nest({
|
|
308
|
+
...Filters.where[0],
|
|
309
|
+
...{ [element]: (0, typeorm_1.MoreThan)(value) }
|
|
310
|
+
});
|
|
311
|
+
break;
|
|
312
|
+
case '>=':
|
|
313
|
+
Filters.where[0] = js_utils_1.Objects.nest({
|
|
314
|
+
...Filters.where[0],
|
|
315
|
+
...{ [element]: (0, typeorm_1.MoreThanOrEqual)(value) }
|
|
316
|
+
});
|
|
317
|
+
break;
|
|
318
|
+
case '<':
|
|
319
|
+
Filters.where[0] = js_utils_1.Objects.nest({
|
|
320
|
+
...Filters.where[0],
|
|
321
|
+
...{ [element]: (0, typeorm_1.LessThan)(value) }
|
|
322
|
+
});
|
|
323
|
+
break;
|
|
324
|
+
case '<=':
|
|
325
|
+
Filters.where[0] = js_utils_1.Objects.nest({
|
|
326
|
+
...Filters.where[0],
|
|
327
|
+
...{ [element]: (0, typeorm_1.LessThanOrEqual)(value) }
|
|
328
|
+
});
|
|
329
|
+
break;
|
|
330
|
+
case 'in':
|
|
331
|
+
Filters.where[0] = js_utils_1.Objects.nest({
|
|
332
|
+
...Filters.where[0],
|
|
333
|
+
...{ [element]: (0, typeorm_1.In)(value) }
|
|
334
|
+
});
|
|
335
|
+
break;
|
|
336
|
+
case 'nin':
|
|
337
|
+
Filters.where[0] = js_utils_1.Objects.nest({
|
|
338
|
+
...Filters.where[0],
|
|
339
|
+
...{ [element]: (0, typeorm_1.Not)((0, typeorm_1.In)(value)) }
|
|
340
|
+
});
|
|
341
|
+
break;
|
|
342
|
+
case 'exists':
|
|
343
|
+
Filters.where[0] = js_utils_1.Objects.nest({
|
|
344
|
+
...Filters.where[0],
|
|
345
|
+
...{ [element]: (0, typeorm_1.Not)((0, typeorm_1.IsNull)()) }
|
|
346
|
+
});
|
|
347
|
+
break;
|
|
348
|
+
case '!exists':
|
|
349
|
+
Filters.where[0] = js_utils_1.Objects.nest({
|
|
350
|
+
...Filters.where[0],
|
|
351
|
+
...{ [element]: (0, typeorm_1.IsNull)() }
|
|
352
|
+
});
|
|
353
|
+
break;
|
|
354
|
+
case 'regexp':
|
|
355
|
+
Filters.where[0] = js_utils_1.Objects.nest({
|
|
356
|
+
...Filters.where[0],
|
|
357
|
+
...{ [element]: (0, typeorm_1.Like)(value) }
|
|
358
|
+
});
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
orFilters.forEach(condition => {
|
|
363
|
+
const element = condition[0];
|
|
364
|
+
const operator = condition[1];
|
|
365
|
+
const value = condition[2];
|
|
366
|
+
switch (operator) {
|
|
367
|
+
case '=':
|
|
368
|
+
Filters.where.push({ [element]: (0, typeorm_1.Equal)(value) });
|
|
369
|
+
break;
|
|
370
|
+
case '!=':
|
|
371
|
+
Filters.where.push({ [element]: (0, typeorm_1.Not)((0, typeorm_1.Equal)(value)) });
|
|
372
|
+
break;
|
|
373
|
+
case '>':
|
|
374
|
+
Filters.where.push({ [element]: (0, typeorm_1.MoreThan)(value) });
|
|
375
|
+
break;
|
|
376
|
+
case '>=':
|
|
377
|
+
Filters.where.push(js_utils_1.Objects.nest({ [element]: (0, typeorm_1.MoreThanOrEqual)(value) }));
|
|
378
|
+
break;
|
|
379
|
+
case '<':
|
|
380
|
+
Filters.where.push({ [element]: (0, typeorm_1.LessThan)(value) });
|
|
381
|
+
break;
|
|
382
|
+
case '<=':
|
|
383
|
+
Filters.where.push({ [element]: (0, typeorm_1.LessThanOrEqual)(value) });
|
|
384
|
+
break;
|
|
385
|
+
case 'in':
|
|
386
|
+
Filters.where.push({ [element]: (0, typeorm_1.In)(value) });
|
|
387
|
+
break;
|
|
388
|
+
case 'nin':
|
|
389
|
+
Filters.where.push({ [element]: (0, typeorm_1.Not)((0, typeorm_1.In)(value)) });
|
|
390
|
+
break;
|
|
391
|
+
case 'exists':
|
|
392
|
+
Filters.where.push({ [element]: (0, typeorm_1.Not)((0, typeorm_1.IsNull)()) });
|
|
393
|
+
break;
|
|
394
|
+
case '!exists':
|
|
395
|
+
Filters.where.push({ [element]: (0, typeorm_1.IsNull)() });
|
|
396
|
+
break;
|
|
397
|
+
case 'regexp':
|
|
398
|
+
Filters.where.push({ [element]: (0, typeorm_1.Like)(value) });
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
return Filters;
|
|
403
|
+
}
|
|
404
|
+
getMongoFilters(filters) {
|
|
405
|
+
const andFilters = this.whereArray;
|
|
406
|
+
const orFilters = this.orWhereArray;
|
|
407
|
+
if (this.relationQuery && this.relationQuery.data) {
|
|
408
|
+
const ids = this.relationQuery.data.map(d => js_utils_1.Ids.objectID(d.id));
|
|
409
|
+
andFilters.push([
|
|
410
|
+
this.relationQuery.relation.inverseSidePropertyPath,
|
|
411
|
+
'in',
|
|
412
|
+
ids
|
|
413
|
+
]);
|
|
414
|
+
}
|
|
415
|
+
if (!andFilters || andFilters.length === 0) {
|
|
416
|
+
return filters;
|
|
417
|
+
}
|
|
418
|
+
const Filters = { where: { $and: [] } };
|
|
419
|
+
andFilters.forEach(condition => {
|
|
420
|
+
let element = condition[0];
|
|
421
|
+
const operator = condition[1];
|
|
422
|
+
let value = condition[2];
|
|
423
|
+
if (element === 'id') {
|
|
424
|
+
element = '_id';
|
|
425
|
+
value = Array.isArray(value)
|
|
426
|
+
? value.map(v => js_utils_1.Ids.objectID(v))
|
|
427
|
+
: js_utils_1.Ids.objectID(value);
|
|
428
|
+
}
|
|
429
|
+
switch (operator) {
|
|
430
|
+
case '=':
|
|
431
|
+
Filters.where.$and.push({ [element]: { $eq: value } });
|
|
432
|
+
break;
|
|
433
|
+
case '!=':
|
|
434
|
+
Filters.where.$and.push({ [element]: { $neq: value } });
|
|
435
|
+
break;
|
|
436
|
+
case '>':
|
|
437
|
+
Filters.where.$and.push({ [element]: { $gt: value } });
|
|
438
|
+
break;
|
|
439
|
+
case '>=':
|
|
440
|
+
Filters.where.$and.push({ [element]: { $gte: value } });
|
|
441
|
+
break;
|
|
442
|
+
case '<':
|
|
443
|
+
Filters.where.$and.push({ [element]: { $lt: value } });
|
|
444
|
+
break;
|
|
445
|
+
case '<=':
|
|
446
|
+
Filters.where.$and.push({ [element]: { $lte: value } });
|
|
447
|
+
break;
|
|
448
|
+
case 'in':
|
|
449
|
+
Filters.where.$and.push({ [element]: { $in: value } });
|
|
450
|
+
break;
|
|
451
|
+
case 'nin':
|
|
452
|
+
Filters.where.$and.push({
|
|
453
|
+
[element]: { $not: { $in: value } }
|
|
454
|
+
});
|
|
455
|
+
break;
|
|
456
|
+
case 'exists':
|
|
457
|
+
Filters.where.$and.push({ [element]: { $exists: true } });
|
|
458
|
+
break;
|
|
459
|
+
case '!exists':
|
|
460
|
+
Filters.where.$and.push({ [element]: { $exists: false } });
|
|
461
|
+
break;
|
|
462
|
+
case 'regex':
|
|
463
|
+
Filters.where.$and.push({ [element]: { $regex: value } });
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
return Filters;
|
|
468
|
+
}
|
|
469
|
+
getOrderBy(filter) {
|
|
470
|
+
if (!this.orderByArray || this.orderByArray.length === 0) {
|
|
471
|
+
return filter;
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
...filter,
|
|
475
|
+
order: {
|
|
476
|
+
[this.orderByArray[0]]: this.orderByArray[1].toUpperCase()
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
getLimit(filter) {
|
|
481
|
+
if (!this.limitNumber || this.limitNumber === 0) {
|
|
482
|
+
this.limitNumber = (this.rawQuery && this.rawQuery.limit) || 50;
|
|
483
|
+
}
|
|
484
|
+
return { ...filter, take: this.limitNumber };
|
|
485
|
+
}
|
|
486
|
+
getSkip(filter) {
|
|
487
|
+
if (!this.offsetNumber) {
|
|
488
|
+
this.offsetNumber = (this.rawQuery && this.rawQuery.skip) || 0;
|
|
489
|
+
}
|
|
490
|
+
return { ...filter, skip: this.offsetNumber };
|
|
491
|
+
}
|
|
492
|
+
getSelect(filter) {
|
|
493
|
+
let select = this.selectArray;
|
|
494
|
+
if (Object.keys(select).length === 0 && select.constructor === Object) {
|
|
495
|
+
select = [''];
|
|
496
|
+
}
|
|
497
|
+
select = select.map(s => {
|
|
498
|
+
s = s.split(' as ')[0];
|
|
499
|
+
s = s.includes('id') ? 'id' : s;
|
|
500
|
+
return s;
|
|
501
|
+
});
|
|
502
|
+
if (select.find(e => e.startsWith('data.'))) {
|
|
503
|
+
select.unshift('data');
|
|
504
|
+
}
|
|
505
|
+
if (!select) {
|
|
506
|
+
return filter;
|
|
507
|
+
}
|
|
508
|
+
return { ...filter, fields: select };
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
exports.TypeOrmConnector = TypeOrmConnector;
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare class PaginationMeta {
|
|
2
|
-
itemCount: number;
|
|
3
|
-
totalItems: number;
|
|
4
|
-
itemsPerPage: number;
|
|
5
|
-
totalPages: number;
|
|
6
|
-
currentPage: number;
|
|
7
|
-
}
|
|
8
|
-
export declare class PaginationLinks {
|
|
9
|
-
first?: string;
|
|
10
|
-
previous?: string;
|
|
11
|
-
next?: string;
|
|
12
|
-
last?: string;
|
|
13
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PaginationLinks = exports.PaginationMeta = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const types_1 = require("../types");
|
|
6
|
-
let PaginationMeta = class PaginationMeta {
|
|
7
|
-
};
|
|
8
|
-
tslib_1.__decorate([
|
|
9
|
-
(0, types_1.Column)('number'),
|
|
10
|
-
(0, types_1.ApiProperty)(),
|
|
11
|
-
tslib_1.__metadata("design:type", Number)
|
|
12
|
-
], PaginationMeta.prototype, "itemCount", void 0);
|
|
13
|
-
tslib_1.__decorate([
|
|
14
|
-
(0, types_1.Column)('number'),
|
|
15
|
-
(0, types_1.ApiProperty)(),
|
|
16
|
-
tslib_1.__metadata("design:type", Number)
|
|
17
|
-
], PaginationMeta.prototype, "totalItems", void 0);
|
|
18
|
-
tslib_1.__decorate([
|
|
19
|
-
(0, types_1.Column)('number'),
|
|
20
|
-
(0, types_1.ApiProperty)(),
|
|
21
|
-
tslib_1.__metadata("design:type", Number)
|
|
22
|
-
], PaginationMeta.prototype, "itemsPerPage", void 0);
|
|
23
|
-
tslib_1.__decorate([
|
|
24
|
-
(0, types_1.Column)('number'),
|
|
25
|
-
(0, types_1.ApiProperty)(),
|
|
26
|
-
tslib_1.__metadata("design:type", Number)
|
|
27
|
-
], PaginationMeta.prototype, "totalPages", void 0);
|
|
28
|
-
tslib_1.__decorate([
|
|
29
|
-
(0, types_1.Column)('number'),
|
|
30
|
-
(0, types_1.ApiProperty)(),
|
|
31
|
-
tslib_1.__metadata("design:type", Number)
|
|
32
|
-
], PaginationMeta.prototype, "currentPage", void 0);
|
|
33
|
-
PaginationMeta = tslib_1.__decorate([
|
|
34
|
-
(0, types_1.InputType)()
|
|
35
|
-
], PaginationMeta);
|
|
36
|
-
exports.PaginationMeta = PaginationMeta;
|
|
37
|
-
let PaginationLinks = class PaginationLinks {
|
|
38
|
-
};
|
|
39
|
-
tslib_1.__decorate([
|
|
40
|
-
(0, types_1.Column)('text'),
|
|
41
|
-
(0, types_1.ApiProperty)(),
|
|
42
|
-
tslib_1.__metadata("design:type", String)
|
|
43
|
-
], PaginationLinks.prototype, "first", void 0);
|
|
44
|
-
tslib_1.__decorate([
|
|
45
|
-
(0, types_1.Column)('text'),
|
|
46
|
-
(0, types_1.ApiProperty)(),
|
|
47
|
-
tslib_1.__metadata("design:type", String)
|
|
48
|
-
], PaginationLinks.prototype, "previous", void 0);
|
|
49
|
-
tslib_1.__decorate([
|
|
50
|
-
(0, types_1.Column)('text'),
|
|
51
|
-
(0, types_1.ApiProperty)(),
|
|
52
|
-
tslib_1.__metadata("design:type", String)
|
|
53
|
-
], PaginationLinks.prototype, "next", void 0);
|
|
54
|
-
tslib_1.__decorate([
|
|
55
|
-
(0, types_1.Column)('text'),
|
|
56
|
-
(0, types_1.ApiProperty)(),
|
|
57
|
-
tslib_1.__metadata("design:type", String)
|
|
58
|
-
], PaginationLinks.prototype, "last", void 0);
|
|
59
|
-
PaginationLinks = tslib_1.__decorate([
|
|
60
|
-
(0, types_1.InputType)()
|
|
61
|
-
], PaginationLinks);
|
|
62
|
-
exports.PaginationLinks = PaginationLinks;
|
package/dist/index.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PaginationMeta = exports.PaginationLinks = exports.loadRelations = exports.TypeOrmConnector = exports.HideField = exports.ObjectType = exports.getModelSchemaRef = exports.Column = exports.PartialType = exports.InputType = exports.OmitType = exports.ApiHideProperty = exports.ApiProperty = exports.modelGeneratorDataSource = exports.getOutputKeys = exports.Fluent = exports.Decorators = exports.createConnection = exports.Collection = exports.BaseConnector = void 0;
|
|
4
|
-
const BaseConnector_1 = require("./BaseConnector");
|
|
5
|
-
Object.defineProperty(exports, "BaseConnector", { enumerable: true, get: function () { return BaseConnector_1.BaseConnector; } });
|
|
6
|
-
const js_utils_1 = require("@goatlab/js-utils");
|
|
7
|
-
Object.defineProperty(exports, "Collection", { enumerable: true, get: function () { return js_utils_1.Collection; } });
|
|
8
|
-
const Fluent_1 = require("./Fluent");
|
|
9
|
-
Object.defineProperty(exports, "Fluent", { enumerable: true, get: function () { return Fluent_1.Fluent; } });
|
|
10
|
-
const generatorDatasource_1 = require("./generatorDatasource");
|
|
11
|
-
Object.defineProperty(exports, "modelGeneratorDataSource", { enumerable: true, get: function () { return generatorDatasource_1.modelGeneratorDataSource; } });
|
|
12
|
-
const outputKeys_1 = require("./outputKeys");
|
|
13
|
-
Object.defineProperty(exports, "getOutputKeys", { enumerable: true, get: function () { return outputKeys_1.getOutputKeys; } });
|
|
14
|
-
const decorators_1 = require("./core/database/decorators");
|
|
15
|
-
Object.defineProperty(exports, "Decorators", { enumerable: true, get: function () { return decorators_1.Decorators; } });
|
|
16
|
-
const types_1 = require("./core/types");
|
|
17
|
-
Object.defineProperty(exports, "ApiProperty", { enumerable: true, get: function () { return types_1.ApiProperty; } });
|
|
18
|
-
Object.defineProperty(exports, "ApiHideProperty", { enumerable: true, get: function () { return types_1.ApiHideProperty; } });
|
|
19
|
-
Object.defineProperty(exports, "OmitType", { enumerable: true, get: function () { return types_1.OmitType; } });
|
|
20
|
-
Object.defineProperty(exports, "InputType", { enumerable: true, get: function () { return types_1.InputType; } });
|
|
21
|
-
Object.defineProperty(exports, "PartialType", { enumerable: true, get: function () { return types_1.PartialType; } });
|
|
22
|
-
Object.defineProperty(exports, "Column", { enumerable: true, get: function () { return types_1.Column; } });
|
|
23
|
-
Object.defineProperty(exports, "getModelSchemaRef", { enumerable: true, get: function () { return types_1.getModelSchemaRef; } });
|
|
24
|
-
Object.defineProperty(exports, "ObjectType", { enumerable: true, get: function () { return types_1.ObjectType; } });
|
|
25
|
-
Object.defineProperty(exports, "HideField", { enumerable: true, get: function () { return types_1.HideField; } });
|
|
26
|
-
const createConnection_1 = require("./core/database/createConnection");
|
|
27
|
-
Object.defineProperty(exports, "createConnection", { enumerable: true, get: function () { return createConnection_1.createConnection; } });
|
|
28
|
-
const TypeOrmConnector_1 = require("./TypeOrmConnector/TypeOrmConnector");
|
|
29
|
-
Object.defineProperty(exports, "TypeOrmConnector", { enumerable: true, get: function () { return TypeOrmConnector_1.TypeOrmConnector; } });
|
|
30
|
-
const loadRelations_1 = require("./loadRelations");
|
|
31
|
-
Object.defineProperty(exports, "loadRelations", { enumerable: true, get: function () { return loadRelations_1.loadRelations; } });
|
|
32
|
-
const pagination_dto_1 = require("./core/dtos/pagination.dto");
|
|
33
|
-
Object.defineProperty(exports, "PaginationLinks", { enumerable: true, get: function () { return pagination_dto_1.PaginationLinks; } });
|
|
34
|
-
Object.defineProperty(exports, "PaginationMeta", { enumerable: true, get: function () { return pagination_dto_1.PaginationMeta; } });
|