@ptc-org/nestjs-query-typegoose 2.0.0-alpha.1 → 2.0.0
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/README.md +1 -1
- package/package.json +9 -10
- package/src/index.d.ts +2 -0
- package/src/index.js.map +1 -0
- package/src/module.d.ts +5 -0
- package/src/module.js +19 -0
- package/src/module.js.map +1 -0
- package/src/providers.d.ts +3 -0
- package/src/providers.js +41 -0
- package/src/providers.js.map +1 -0
- package/src/query/aggregate.builder.d.ts +25 -0
- package/src/query/aggregate.builder.js +111 -0
- package/src/query/aggregate.builder.js.map +1 -0
- package/src/query/comparison.builder.d.ts +29 -0
- package/src/query/comparison.builder.js +101 -0
- package/src/query/comparison.builder.js.map +1 -0
- package/src/query/filter-query.builder.d.ts +44 -0
- package/src/query/filter-query.builder.js +85 -0
- package/src/query/filter-query.builder.js.map +1 -0
- package/src/query/helpers.d.ts +1 -0
- package/src/query/helpers.js +8 -0
- package/src/query/helpers.js.map +1 -0
- package/src/query/index.d.ts +4 -0
- package/src/query/index.js +8 -0
- package/src/query/index.js.map +1 -0
- package/src/query/where.builder.d.ts +24 -0
- package/src/query/where.builder.js +72 -0
- package/src/query/where.builder.js.map +1 -0
- package/src/services/index.d.ts +1 -0
- package/src/services/index.js +5 -0
- package/src/services/index.js.map +1 -0
- package/src/services/reference-query.service.d.ts +34 -0
- package/src/services/reference-query.service.js +237 -0
- package/src/services/reference-query.service.js.map +1 -0
- package/src/services/typegoose-query-service.d.ts +134 -0
- package/src/services/typegoose-query-service.js +246 -0
- package/src/services/typegoose-query-service.js.map +1 -0
- package/src/typegoose-interface.helpers.d.ts +14 -0
- package/src/typegoose-interface.helpers.js +3 -0
- package/src/typegoose-interface.helpers.js.map +1 -0
- package/src/typegoose-types.helper.d.ts +40 -0
- package/src/typegoose-types.helper.js +40 -0
- package/src/typegoose-types.helper.js.map +1 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypegooseQueryService = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const typegoose_1 = require("@typegoose/typegoose");
|
|
6
|
+
const query_1 = require("../query");
|
|
7
|
+
const reference_query_service_1 = require("./reference-query.service");
|
|
8
|
+
class TypegooseQueryService extends reference_query_service_1.ReferenceQueryService {
|
|
9
|
+
constructor(Model, filterQueryBuilder = new query_1.FilterQueryBuilder(Model)) {
|
|
10
|
+
super(Model);
|
|
11
|
+
this.Model = Model;
|
|
12
|
+
this.filterQueryBuilder = filterQueryBuilder;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Query for multiple entities, using a Query from `@ptc-org/nestjs-query-core`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const todoItems = await this.service.query({
|
|
20
|
+
* filter: { title: { eq: 'Foo' } },
|
|
21
|
+
* paging: { limit: 10 },
|
|
22
|
+
* sorting: [{ field: "create", direction: SortDirection.DESC }],
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
* @param query - The Query used to filter, page, and sort rows.
|
|
26
|
+
*/
|
|
27
|
+
async query(query) {
|
|
28
|
+
const { filterQuery, options } = this.filterQueryBuilder.buildQuery(query);
|
|
29
|
+
const entities = await this.Model.find(filterQuery, {}, options).exec();
|
|
30
|
+
return entities;
|
|
31
|
+
}
|
|
32
|
+
async aggregate(filter, aggregateQuery) {
|
|
33
|
+
const { aggregate, filterQuery, options } = this.filterQueryBuilder.buildAggregateQuery(aggregateQuery, filter);
|
|
34
|
+
const aggPipeline = [{ $match: filterQuery }, { $group: aggregate }];
|
|
35
|
+
if (options.sort) {
|
|
36
|
+
aggPipeline.push({ $sort: options.sort ?? {} });
|
|
37
|
+
}
|
|
38
|
+
const aggResult = await this.Model.aggregate(aggPipeline).exec();
|
|
39
|
+
return query_1.AggregateBuilder.convertToAggregateResponse(aggResult);
|
|
40
|
+
}
|
|
41
|
+
count(filter) {
|
|
42
|
+
const filterQuery = this.filterQueryBuilder.buildFilterQuery(filter);
|
|
43
|
+
return this.Model.countDocuments(filterQuery).exec();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Find an entity by it's `id`.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const todoItem = await this.service.findById(1);
|
|
51
|
+
* ```
|
|
52
|
+
* @param id - The id of the record to find.
|
|
53
|
+
* @param opts - Additional options
|
|
54
|
+
*/
|
|
55
|
+
async findById(id, opts) {
|
|
56
|
+
const filterQuery = this.filterQueryBuilder.buildIdFilterQuery(id, opts?.filter);
|
|
57
|
+
const doc = await this.Model.findOne(filterQuery);
|
|
58
|
+
if (!doc) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
return doc;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Gets an entity by it's `id`. If the entity is not found a rejected promise is returned.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* try {
|
|
69
|
+
* const todoItem = await this.service.getById(1);
|
|
70
|
+
* } catch(e) {
|
|
71
|
+
* console.error('Unable to find entity with id = 1');
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
* @param id - The id of the record to find.
|
|
75
|
+
* @param opts - Additional options
|
|
76
|
+
*/
|
|
77
|
+
async getById(id, opts) {
|
|
78
|
+
const doc = await this.findById(id, opts);
|
|
79
|
+
if (!doc) {
|
|
80
|
+
throw new common_1.NotFoundException(`Unable to find ${this.Model.modelName} with id: ${id}`);
|
|
81
|
+
}
|
|
82
|
+
return doc;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Creates a single entity.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const todoItem = await this.service.createOne({title: 'Todo Item', completed: false });
|
|
90
|
+
* ```
|
|
91
|
+
* @param record - The entity to create.
|
|
92
|
+
*/
|
|
93
|
+
async createOne(record) {
|
|
94
|
+
this.ensureIdIsNotPresent(record);
|
|
95
|
+
const doc = await this.Model.create(record);
|
|
96
|
+
return doc;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Create multiple entities.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const todoItem = await this.service.createMany([
|
|
104
|
+
* {title: 'Todo Item 1', completed: false },
|
|
105
|
+
* {title: 'Todo Item 2', completed: true },
|
|
106
|
+
* ]);
|
|
107
|
+
* ```
|
|
108
|
+
* @param records - The entities to create.
|
|
109
|
+
*/
|
|
110
|
+
async createMany(records) {
|
|
111
|
+
records.forEach((r) => this.ensureIdIsNotPresent(r));
|
|
112
|
+
const entities = await this.Model.create(records);
|
|
113
|
+
return entities;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Update an entity.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const updatedEntity = await this.service.updateOne(1, { completed: true });
|
|
121
|
+
* ```
|
|
122
|
+
* @param id - The `id` of the record.
|
|
123
|
+
* @param update - A `Partial` of the entity with fields to update.
|
|
124
|
+
* @param opts - Additional options
|
|
125
|
+
*/
|
|
126
|
+
async updateOne(id, update, opts) {
|
|
127
|
+
this.ensureIdIsNotPresent(update);
|
|
128
|
+
const filterQuery = this.filterQueryBuilder.buildIdFilterQuery(id, opts?.filter);
|
|
129
|
+
const doc = await this.Model.findOneAndUpdate(filterQuery, this.getUpdateQuery(update), {
|
|
130
|
+
new: true
|
|
131
|
+
});
|
|
132
|
+
if (!doc) {
|
|
133
|
+
throw new common_1.NotFoundException(`Unable to find ${this.Model.modelName} with id: ${id}`);
|
|
134
|
+
}
|
|
135
|
+
return doc;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Update multiple entities with a `@ptc-org/nestjs-query-core` Filter.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* const { updatedCount } = await this.service.updateMany(
|
|
143
|
+
* { completed: true }, // the update to apply
|
|
144
|
+
* { title: { eq: 'Foo Title' } } // Filter to find records to update
|
|
145
|
+
* );
|
|
146
|
+
* ```
|
|
147
|
+
* @param update - A `Partial` of entity with the fields to update
|
|
148
|
+
* @param filter - A Filter used to find the records to update
|
|
149
|
+
*/
|
|
150
|
+
async updateMany(update, filter) {
|
|
151
|
+
this.ensureIdIsNotPresent(update);
|
|
152
|
+
const filterQuery = this.filterQueryBuilder.buildFilterQuery(filter);
|
|
153
|
+
const res = await this.Model.updateMany(filterQuery, this.getUpdateQuery(update)).exec();
|
|
154
|
+
return { updatedCount: res.modifiedCount || 0 };
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Delete an entity by `id`.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
*
|
|
161
|
+
* ```ts
|
|
162
|
+
* const deletedTodo = await this.service.deleteOne(1);
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @param id - The `id` of the entity to delete.
|
|
166
|
+
* @param opts - Additional filter to use when finding the entity to delete.
|
|
167
|
+
*/
|
|
168
|
+
async deleteOne(id, opts) {
|
|
169
|
+
const filterQuery = this.filterQueryBuilder.buildIdFilterQuery(id, opts?.filter);
|
|
170
|
+
const doc = await this.Model.findOneAndDelete(filterQuery);
|
|
171
|
+
if (!doc) {
|
|
172
|
+
throw new common_1.NotFoundException(`Unable to find ${this.Model.modelName} with id: ${id}`);
|
|
173
|
+
}
|
|
174
|
+
return doc;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Delete multiple records with a `@ptc-org/nestjs-query-core` `Filter`.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* const { deletedCount } = this.service.deleteMany({
|
|
183
|
+
* created: { lte: new Date('2020-1-1') }
|
|
184
|
+
* });
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @param filter - A `Filter` to find records to delete.
|
|
188
|
+
*/
|
|
189
|
+
async deleteMany(filter) {
|
|
190
|
+
const filterQuery = this.filterQueryBuilder.buildFilterQuery(filter);
|
|
191
|
+
const res = await this.Model.deleteMany(filterQuery).exec();
|
|
192
|
+
return { deletedCount: res.deletedCount || 0 };
|
|
193
|
+
}
|
|
194
|
+
ensureIdIsNotPresent(e) {
|
|
195
|
+
if (Object.entries(e).find(([k, v]) => (k === 'id' || k === '_id') && typeof v !== `undefined`)) {
|
|
196
|
+
throw new Error('Id cannot be specified when updating or creating');
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
getUpdateQuery(entity) {
|
|
200
|
+
if (entity instanceof this.Model) {
|
|
201
|
+
return entity.modifiedPaths().reduce((update, k) =>
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
203
|
+
({ ...update, [k]: entity.get(k) }), {});
|
|
204
|
+
}
|
|
205
|
+
const arrayUpdateQuery = this.buildArrayUpdateQuery(entity);
|
|
206
|
+
return { ...entity, ...arrayUpdateQuery };
|
|
207
|
+
}
|
|
208
|
+
buildArrayUpdateQuery(entity) {
|
|
209
|
+
// eslint-disable-next-line prefer-const
|
|
210
|
+
let query = {
|
|
211
|
+
$addToSet: {},
|
|
212
|
+
$pull: {}
|
|
213
|
+
};
|
|
214
|
+
Object.keys(entity).forEach((key) => {
|
|
215
|
+
if (this.Model.schema.path(key) instanceof typegoose_1.mongoose.Schema.Types.Array && typeof entity[key] === 'object') {
|
|
216
|
+
// Converting the type of the object as it has the custom array input type.
|
|
217
|
+
const convert = entity[key];
|
|
218
|
+
if (Object.prototype.hasOwnProperty.call(convert, 'push')) {
|
|
219
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
220
|
+
query.$addToSet[key] = { $each: convert.push };
|
|
221
|
+
}
|
|
222
|
+
if (Object.prototype.hasOwnProperty.call(convert, 'pull')) {
|
|
223
|
+
query.$pull[key] = {};
|
|
224
|
+
convert.pull.forEach((item, index) => {
|
|
225
|
+
Object.keys(item).forEach((innerKey) => {
|
|
226
|
+
if (query.$pull[key][innerKey] !== undefined) {
|
|
227
|
+
query.$pull[key][innerKey].$in.push(convert.pull[index][innerKey]);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
query.$pull[key][innerKey] = { $in: [convert.pull[index][innerKey]] };
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (Object.prototype.hasOwnProperty.call(entity[key], 'push') ||
|
|
236
|
+
Object.prototype.hasOwnProperty.call(entity[key], 'pull')) {
|
|
237
|
+
// eslint-disable-next-line no-param-reassign
|
|
238
|
+
delete entity[key];
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return query;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
exports.TypegooseQueryService = TypegooseQueryService;
|
|
246
|
+
//# sourceMappingURL=typegoose-query-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typegoose-query-service.js","sourceRoot":"","sources":["../../../../../packages/query-typegoose/src/services/typegoose-query-service.ts"],"names":[],"mappings":";;;AAAA,2CAAkD;AAelD,oDAA8E;AAI9E,oCAA+D;AAE/D,uEAAiE;AAMjE,MAAa,qBAA2C,SAAQ,+CAA6B;IAC3F,YACW,KAAwC,EACxC,qBAAiD,IAAI,0BAAkB,CAAC,KAAK,CAAC;QAEvF,KAAK,CAAC,KAAK,CAAC,CAAA;QAHH,UAAK,GAAL,KAAK,CAAmC;QACxC,uBAAkB,GAAlB,kBAAkB,CAA4D;IAGzF,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,KAAK,CAAC,KAAoB;QAC9B,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,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,CAAC,KAAK,CAAC,CAAC,QAAwB,CAAC,CAAC,EAAE,CAAA;6BACtF;wBACH,CAAC,CAAC,CAAA;oBACJ,CAAC,CAAC,CAAA;iBACH;gBAED,IACE,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,GAAmB,CAAC,EAAE,MAAM,CAAC;oBACzE,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,GAAmB,CAAC,EAAE,MAAM,CAAC,EACzE;oBACA,6CAA6C;oBAC7C,OAAO,MAAM,CAAC,GAAmB,CAAC,CAAA;iBACnC;aACF;QACH,CAAC,CAAC,CAAA;QAEF,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AApQD,sDAoQC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { mongoose } from '@typegoose/typegoose';
|
|
2
|
+
export interface TypegooseClass {
|
|
3
|
+
new (...args: any[]): any;
|
|
4
|
+
}
|
|
5
|
+
export interface TypegooseClassWrapper {
|
|
6
|
+
typegooseClass: TypegooseClass;
|
|
7
|
+
}
|
|
8
|
+
export interface TypegooseClassWithOptions extends TypegooseClassWrapper {
|
|
9
|
+
schemaOptions?: mongoose.SchemaOptions;
|
|
10
|
+
discriminators?: (TypegooseClass | TypegooseDiscriminator)[];
|
|
11
|
+
}
|
|
12
|
+
export interface TypegooseDiscriminator extends TypegooseClassWrapper {
|
|
13
|
+
discriminatorId?: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typegoose-interface.helpers.js","sourceRoot":"","sources":["../../../../packages/query-typegoose/src/typegoose-interface.helpers.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { mongoose } from '@typegoose/typegoose';
|
|
2
|
+
export type ReferenceOptions = {
|
|
3
|
+
type: mongoose.SchemaType;
|
|
4
|
+
ref: string;
|
|
5
|
+
};
|
|
6
|
+
export type UpdateArrayQuery<T> = {
|
|
7
|
+
$addToSet: {
|
|
8
|
+
[key: string]: {
|
|
9
|
+
$each: T[];
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
$pull: {
|
|
13
|
+
[key: string]: {
|
|
14
|
+
[key: string]: {
|
|
15
|
+
$in: T[keyof T][];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export declare function isReferenceOptions(options: unknown): options is ReferenceOptions;
|
|
21
|
+
export type SchemaTypeWithReferenceOptions = {
|
|
22
|
+
options: ReferenceOptions;
|
|
23
|
+
};
|
|
24
|
+
export declare function isSchemaTypeWithReferenceOptions(type: unknown): type is SchemaTypeWithReferenceOptions;
|
|
25
|
+
export type EmbeddedSchemaTypeOptions = {
|
|
26
|
+
$embeddedSchemaType: {
|
|
27
|
+
options: ReferenceOptions;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export declare function isEmbeddedSchemaTypeOptions(options: unknown): options is EmbeddedSchemaTypeOptions;
|
|
31
|
+
export type VirtualReferenceOptions = {
|
|
32
|
+
ref: string;
|
|
33
|
+
localField: string;
|
|
34
|
+
foreignField: string;
|
|
35
|
+
};
|
|
36
|
+
export declare function isVirtualReferenceOptions(options: unknown): options is VirtualReferenceOptions;
|
|
37
|
+
export type VirtualTypeWithOptions = {
|
|
38
|
+
options: VirtualReferenceOptions;
|
|
39
|
+
};
|
|
40
|
+
export declare function isVirtualTypeWithReferenceOptions(virtualType: unknown): virtualType is VirtualTypeWithOptions;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isVirtualTypeWithReferenceOptions = exports.isVirtualReferenceOptions = exports.isEmbeddedSchemaTypeOptions = exports.isSchemaTypeWithReferenceOptions = exports.isReferenceOptions = void 0;
|
|
4
|
+
function isReferenceOptions(options) {
|
|
5
|
+
return (typeof options === 'object' &&
|
|
6
|
+
options !== null &&
|
|
7
|
+
'type' in options &&
|
|
8
|
+
'ref' in options &&
|
|
9
|
+
typeof options.ref === 'string');
|
|
10
|
+
}
|
|
11
|
+
exports.isReferenceOptions = isReferenceOptions;
|
|
12
|
+
function isSchemaTypeWithReferenceOptions(type) {
|
|
13
|
+
if (type && typeof type === 'object' && 'options' in type) {
|
|
14
|
+
const { options } = type;
|
|
15
|
+
return isReferenceOptions(options);
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
exports.isSchemaTypeWithReferenceOptions = isSchemaTypeWithReferenceOptions;
|
|
20
|
+
function isEmbeddedSchemaTypeOptions(options) {
|
|
21
|
+
if (options && typeof options === 'object' && '$embeddedSchemaType' in options) {
|
|
22
|
+
const { $embeddedSchemaType } = options;
|
|
23
|
+
return isReferenceOptions($embeddedSchemaType.options);
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
exports.isEmbeddedSchemaTypeOptions = isEmbeddedSchemaTypeOptions;
|
|
28
|
+
function isVirtualReferenceOptions(options) {
|
|
29
|
+
return (typeof options === 'object' && options !== null && 'ref' in options && 'localField' in options && 'foreignField' in options);
|
|
30
|
+
}
|
|
31
|
+
exports.isVirtualReferenceOptions = isVirtualReferenceOptions;
|
|
32
|
+
function isVirtualTypeWithReferenceOptions(virtualType) {
|
|
33
|
+
if (virtualType && typeof virtualType === 'object' && 'options' in virtualType) {
|
|
34
|
+
const { options } = virtualType;
|
|
35
|
+
return isVirtualReferenceOptions(options);
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
exports.isVirtualTypeWithReferenceOptions = isVirtualTypeWithReferenceOptions;
|
|
40
|
+
//# sourceMappingURL=typegoose-types.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typegoose-types.helper.js","sourceRoot":"","sources":["../../../../packages/query-typegoose/src/typegoose-types.helper.ts"],"names":[],"mappings":";;;AA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