@ptc-org/nestjs-query-mongoose 1.0.0-alpha.1 → 1.1.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.
Files changed (42) hide show
  1. package/README.md +8 -7
  2. package/package.json +5 -5
  3. package/src/index.d.ts +2 -0
  4. package/src/index.js +3 -3
  5. package/src/index.js.map +1 -0
  6. package/src/module.d.ts +6 -0
  7. package/src/module.js +19 -0
  8. package/src/module.js.map +1 -0
  9. package/src/mongoose-types.helper.d.ts +26 -0
  10. package/src/mongoose-types.helper.js +42 -0
  11. package/src/mongoose-types.helper.js.map +1 -0
  12. package/src/providers.d.ts +8 -0
  13. package/src/providers.js +25 -0
  14. package/src/providers.js.map +1 -0
  15. package/src/query/aggregate.builder.d.ts +25 -0
  16. package/src/query/aggregate.builder.js +111 -0
  17. package/src/query/aggregate.builder.js.map +1 -0
  18. package/src/query/comparison.builder.d.ts +29 -0
  19. package/src/query/comparison.builder.js +101 -0
  20. package/src/query/comparison.builder.js.map +1 -0
  21. package/src/query/filter-query.builder.d.ts +44 -0
  22. package/src/query/filter-query.builder.js +85 -0
  23. package/src/query/filter-query.builder.js.map +1 -0
  24. package/src/query/helpers.d.ts +1 -0
  25. package/src/query/helpers.js +8 -0
  26. package/src/query/helpers.js.map +1 -0
  27. package/src/query/index.d.ts +4 -0
  28. package/src/query/index.js +8 -0
  29. package/src/query/index.js.map +1 -0
  30. package/src/query/where.builder.d.ts +24 -0
  31. package/src/query/where.builder.js +72 -0
  32. package/src/query/where.builder.js.map +1 -0
  33. package/src/services/index.d.ts +1 -0
  34. package/src/services/index.js +5 -0
  35. package/src/services/index.js.map +1 -0
  36. package/src/services/mongoose-query.service.d.ts +145 -0
  37. package/src/services/mongoose-query.service.js +222 -0
  38. package/src/services/mongoose-query.service.js.map +1 -0
  39. package/src/services/reference-query.service.d.ts +28 -0
  40. package/src/services/reference-query.service.js +233 -0
  41. package/src/services/reference-query.service.js.map +1 -0
  42. package/CHANGELOG.md +0 -159
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilterQueryBuilder = void 0;
4
+ const nestjs_query_core_1 = require("@ptc-org/nestjs-query-core");
5
+ const aggregate_builder_1 = require("./aggregate.builder");
6
+ const helpers_1 = require("./helpers");
7
+ const where_builder_1 = require("./where.builder");
8
+ const MONGOOSE_SORT_DIRECTION = {
9
+ [nestjs_query_core_1.SortDirection.ASC]: 1,
10
+ [nestjs_query_core_1.SortDirection.DESC]: -1
11
+ };
12
+ /**
13
+ * @internal
14
+ *
15
+ * Class that will convert a Query into a `typeorm` Query Builder.
16
+ */
17
+ class FilterQueryBuilder {
18
+ constructor(Model, whereBuilder = new where_builder_1.WhereBuilder(Model), aggregateBuilder = new aggregate_builder_1.AggregateBuilder()) {
19
+ this.Model = Model;
20
+ this.whereBuilder = whereBuilder;
21
+ this.aggregateBuilder = aggregateBuilder;
22
+ }
23
+ buildQuery({ filter, paging, sorting }) {
24
+ return {
25
+ filterQuery: this.buildFilterQuery(filter),
26
+ options: { limit: paging?.limit, skip: paging?.offset, sort: this.buildSorting(sorting) }
27
+ };
28
+ }
29
+ buildAggregateQuery(aggregate, filter) {
30
+ return {
31
+ filterQuery: this.buildFilterQuery(filter),
32
+ aggregate: this.aggregateBuilder.build(aggregate),
33
+ options: { sort: this.buildAggregateSorting(aggregate) }
34
+ };
35
+ }
36
+ buildIdAggregateQuery(id, filter, aggregate) {
37
+ return {
38
+ filterQuery: this.buildIdFilterQuery(id, filter),
39
+ aggregate: this.aggregateBuilder.build(aggregate),
40
+ options: { sort: this.buildAggregateSorting(aggregate) }
41
+ };
42
+ }
43
+ buildIdFilterQuery(id, filter) {
44
+ return {
45
+ ...this.buildFilterQuery(filter),
46
+ _id: Array.isArray(id) ? { $in: id } : id
47
+ };
48
+ }
49
+ /**
50
+ * Applies the filter from a Query to a `typeorm` QueryBuilder.
51
+ *
52
+ * @param filter - the filter.
53
+ */
54
+ buildFilterQuery(filter) {
55
+ if (!filter) {
56
+ return {};
57
+ }
58
+ return this.whereBuilder.build(filter);
59
+ }
60
+ /**
61
+ * Applies the ORDER BY clause to a `typeorm` QueryBuilder.
62
+ * @param sorts - an array of SortFields to create the ORDER BY clause.
63
+ */
64
+ buildSorting(sorts) {
65
+ if (!sorts) {
66
+ return undefined;
67
+ }
68
+ return sorts.reduce((sort, sortField) => {
69
+ const field = (0, helpers_1.getSchemaKey)(sortField.field.toString());
70
+ const direction = MONGOOSE_SORT_DIRECTION[sortField.direction];
71
+ return { ...sort, [field]: direction };
72
+ }, {});
73
+ }
74
+ buildAggregateSorting(aggregate) {
75
+ const aggregateGroupBy = this.aggregateBuilder.getGroupBySelects(aggregate.groupBy);
76
+ if (!aggregateGroupBy) {
77
+ return undefined;
78
+ }
79
+ return aggregateGroupBy.reduce((sort, sortField) => {
80
+ return { ...sort, [(0, helpers_1.getSchemaKey)(sortField)]: MONGOOSE_SORT_DIRECTION[nestjs_query_core_1.SortDirection.ASC] };
81
+ }, {});
82
+ }
83
+ }
84
+ exports.FilterQueryBuilder = FilterQueryBuilder;
85
+ //# sourceMappingURL=filter-query.builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter-query.builder.js","sourceRoot":"","sources":["../../../../../packages/query-mongoose/src/query/filter-query.builder.ts"],"names":[],"mappings":";;;AAAA,kEAAoG;AAGpG,2DAAiF;AACjF,uCAAwC;AACxC,mDAA8C;AAE9C,MAAM,uBAAuB,GAAkC;IAC7D,CAAC,iCAAa,CAAC,GAAG,CAAC,EAAE,CAAC;IACtB,CAAC,iCAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;CACzB,CAAA;AAYD;;;;GAIG;AACH,MAAa,kBAAkB;IAC7B,YACW,KAA4B,EAC5B,eAAqC,IAAI,4BAAY,CAAS,KAAK,CAAC,EACpE,mBAA6C,IAAI,oCAAgB,EAAU;QAF3E,UAAK,GAAL,KAAK,CAAuB;QAC5B,iBAAY,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,gBAAgB,CAAC,MAAuB;QACtC,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,EAAE,CAAA;SACV;QACD,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACxC,CAAC;IAED;;;OAGG;IACH,YAAY,CAAC,KAA2B;QACtC,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,SAAS,CAAA;SACjB;QACD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAkB,EAAE,SAA4B,EAAE,EAAE;YACvE,MAAM,KAAK,GAAG,IAAA,sBAAY,EAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;YACtD,MAAM,SAAS,GAAG,uBAAuB,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;YAC9D,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,CAAA;QACxC,CAAC,EAAE,EAAE,CAAC,CAAA;IACR,CAAC;IAEO,qBAAqB,CAAC,SAAiC;QAC7D,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;QACnF,IAAI,CAAC,gBAAgB,EAAE;YACrB,OAAO,SAAS,CAAA;SACjB;QACD,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC,IAAkB,EAAE,SAAS,EAAE,EAAE;YAC/D,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC,IAAA,sBAAY,EAAC,SAAS,CAAC,CAAC,EAAE,uBAAuB,CAAC,iCAAa,CAAC,GAAG,CAAC,EAAE,CAAA;QAC3F,CAAC,EAAE,EAAE,CAAC,CAAA;IACR,CAAC;CACF;AA7ED,gDA6EC"}
@@ -0,0 +1 @@
1
+ export declare function getSchemaKey(key: string): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSchemaKey = void 0;
4
+ function getSchemaKey(key) {
5
+ return key === 'id' ? '_id' : key;
6
+ }
7
+ exports.getSchemaKey = getSchemaKey;
8
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../../packages/query-mongoose/src/query/helpers.ts"],"names":[],"mappings":";;;AAAA,SAAgB,YAAY,CAAC,GAAW;IACtC,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAA;AACnC,CAAC;AAFD,oCAEC"}
@@ -0,0 +1,4 @@
1
+ export * from './aggregate.builder';
2
+ export * from './comparison.builder';
3
+ export * from './filter-query.builder';
4
+ export * from './where.builder';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./aggregate.builder"), exports);
5
+ (0, tslib_1.__exportStar)(require("./comparison.builder"), exports);
6
+ (0, tslib_1.__exportStar)(require("./filter-query.builder"), exports);
7
+ (0, tslib_1.__exportStar)(require("./where.builder"), exports);
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/query-mongoose/src/query/index.ts"],"names":[],"mappings":";;;AAAA,mEAAmC;AACnC,oEAAoC;AACpC,sEAAsC;AACtC,+DAA+B"}
@@ -0,0 +1,24 @@
1
+ import { Filter } from '@ptc-org/nestjs-query-core';
2
+ import { Document, FilterQuery, Model as MongooseModel } from 'mongoose';
3
+ import { ComparisonBuilder } from './comparison.builder';
4
+ /**
5
+ * @internal
6
+ * Builds a WHERE clause from a Filter.
7
+ */
8
+ export declare class WhereBuilder<Entity extends Document> {
9
+ readonly Model: MongooseModel<Entity>;
10
+ readonly comparisonBuilder: ComparisonBuilder<Entity>;
11
+ constructor(Model: MongooseModel<Entity>, comparisonBuilder?: ComparisonBuilder<Entity>);
12
+ /**
13
+ * Builds a WHERE clause from a Filter.
14
+ * @param filter - the filter to build the WHERE clause from.
15
+ */
16
+ build(filter: Filter<Entity>): FilterQuery<Entity>;
17
+ /**
18
+ * Creates field comparisons from a filter. This method will ignore and/or properties.
19
+ * @param filter - the filter with fields to create comparisons for.
20
+ */
21
+ private filterFields;
22
+ private getField;
23
+ private withFilterComparison;
24
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WhereBuilder = void 0;
4
+ const comparison_builder_1 = require("./comparison.builder");
5
+ /**
6
+ * @internal
7
+ * Builds a WHERE clause from a Filter.
8
+ */
9
+ class WhereBuilder {
10
+ constructor(Model, comparisonBuilder = new comparison_builder_1.ComparisonBuilder(Model)) {
11
+ this.Model = Model;
12
+ this.comparisonBuilder = comparisonBuilder;
13
+ }
14
+ /**
15
+ * Builds a WHERE clause from a Filter.
16
+ * @param filter - the filter to build the WHERE clause from.
17
+ */
18
+ build(filter) {
19
+ const { and, or } = filter;
20
+ let ands = [];
21
+ let ors = [];
22
+ let filterQuery = {};
23
+ if (and && and.length) {
24
+ ands = and.map((f) => this.build(f));
25
+ }
26
+ if (or && or.length) {
27
+ ors = or.map((f) => this.build(f));
28
+ }
29
+ const filterAnds = this.filterFields(filter);
30
+ if (filterAnds) {
31
+ ands = [...ands, filterAnds];
32
+ }
33
+ if (ands.length) {
34
+ filterQuery = { ...filterQuery, $and: ands };
35
+ }
36
+ if (ors.length) {
37
+ filterQuery = { ...filterQuery, $or: ors };
38
+ }
39
+ return filterQuery;
40
+ }
41
+ /**
42
+ * Creates field comparisons from a filter. This method will ignore and/or properties.
43
+ * @param filter - the filter with fields to create comparisons for.
44
+ */
45
+ filterFields(filter) {
46
+ const ands = Object.keys(filter)
47
+ .filter((f) => f !== 'and' && f !== 'or')
48
+ .map((field) => this.withFilterComparison(field, this.getField(filter, field)));
49
+ if (ands.length === 1) {
50
+ return ands[0];
51
+ }
52
+ if (ands.length) {
53
+ return { $and: ands };
54
+ }
55
+ return undefined;
56
+ }
57
+ getField(obj, field) {
58
+ return obj[field];
59
+ }
60
+ withFilterComparison(field, cmp) {
61
+ const opts = Object.keys(cmp);
62
+ if (opts.length === 1) {
63
+ const cmpType = opts[0];
64
+ return this.comparisonBuilder.build(field, cmpType, cmp[cmpType]);
65
+ }
66
+ return {
67
+ $or: opts.map((cmpType) => this.comparisonBuilder.build(field, cmpType, cmp[cmpType]))
68
+ };
69
+ }
70
+ }
71
+ exports.WhereBuilder = WhereBuilder;
72
+ //# sourceMappingURL=where.builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"where.builder.js","sourceRoot":"","sources":["../../../../../packages/query-mongoose/src/query/where.builder.ts"],"names":[],"mappings":";;;AAGA,6DAA+E;AAE/E;;;GAGG;AACH,MAAa,YAAY;IACvB,YACW,KAA4B,EAC5B,oBAA+C,IAAI,sCAAiB,CAAC,KAAK,CAAC;QAD3E,UAAK,GAAL,KAAK,CAAuB;QAC5B,sBAAiB,GAAjB,iBAAiB,CAA0D;IACnF,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,MAAsB;QAC1B,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,MAAM,CAAA;QAC1B,IAAI,IAAI,GAA0B,EAAE,CAAA;QACpC,IAAI,GAAG,GAA0B,EAAE,CAAA;QACnC,IAAI,WAAW,GAAwB,EAAE,CAAA;QACzC,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE;YACrB,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;SACrC;QACD,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE;YACnB,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;SACnC;QACD,MAAM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YACrB,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;YACvB,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,CAAqC,CAAC,CAAA;SACtG;QACD,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,CAAqC,CAAC,CAAC;SACpG,CAAA;IAC1B,CAAC;CACF;AApED,oCAoEC"}
@@ -0,0 +1 @@
1
+ export * from './mongoose-query.service';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./mongoose-query.service"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/query-mongoose/src/services/index.ts"],"names":[],"mappings":";;;AAAA,wEAAwC"}
@@ -0,0 +1,145 @@
1
+ import { AggregateQuery, AggregateResponse, DeepPartial, DeleteManyResponse, DeleteOneOptions, Filter, FindByIdOptions, GetByIdOptions, Query, QueryService, UpdateManyResponse, UpdateOneOptions } from '@ptc-org/nestjs-query-core';
2
+ import { Document, Model as MongooseModel } from 'mongoose';
3
+ import { FilterQueryBuilder } from '../query';
4
+ import { ReferenceQueryService } from './reference-query.service';
5
+ /**
6
+ * Base class for all query services that use Typegoose.
7
+ *
8
+ * @example
9
+ *
10
+ * ```ts
11
+ * @QueryService(TodoItemEntity)
12
+ * export class TodoItemService extends TypegooseQueryService<TodoItemEntity> {
13
+ * constructor(
14
+ * @InjectModel(TodoItemEntity) model: ReturnModelType<typeof TodoItemEntity>,
15
+ * ) {
16
+ * super(model);
17
+ * }
18
+ * }
19
+ * ```
20
+ */
21
+ export declare class MongooseQueryService<Entity extends Document> extends ReferenceQueryService<Entity> implements QueryService<Entity, DeepPartial<Entity>, DeepPartial<Entity>> {
22
+ readonly Model: MongooseModel<Entity>;
23
+ readonly filterQueryBuilder: FilterQueryBuilder<Entity>;
24
+ constructor(Model: MongooseModel<Entity>, filterQueryBuilder?: FilterQueryBuilder<Entity>);
25
+ /**
26
+ * Query for multiple entities, using a Query from `@ptc-org/nestjs-query-core`.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const todoItems = await this.service.query({
31
+ * filter: { title: { eq: 'Foo' } },
32
+ * paging: { limit: 10 },
33
+ * sorting: [{ field: "create", direction: SortDirection.DESC }],
34
+ * });
35
+ * ```
36
+ * @param query - The Query used to filter, page, and sort rows.
37
+ */
38
+ query(query: Query<Entity>): Promise<Entity[]>;
39
+ aggregate(filter: Filter<Entity>, aggregateQuery: AggregateQuery<Entity>): Promise<AggregateResponse<Entity>[]>;
40
+ count(filter: Filter<Entity>): Promise<number>;
41
+ /**
42
+ * Find an entity by it's `id`.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const todoItem = await this.service.findById(1);
47
+ * ```
48
+ * @param id - The id of the record to find.
49
+ * @param opts - Additional options
50
+ */
51
+ findById(id: string | number, opts?: FindByIdOptions<Entity>): Promise<Entity | undefined>;
52
+ /**
53
+ * Gets an entity by it's `id`. If the entity is not found a rejected promise is returned.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * try {
58
+ * const todoItem = await this.service.getById(1);
59
+ * } catch(e) {
60
+ * console.error('Unable to find entity with id = 1');
61
+ * }
62
+ * ```
63
+ * @param id - The id of the record to find.
64
+ * @param opts - Additional options
65
+ */
66
+ getById(id: string, opts?: GetByIdOptions<Entity>): Promise<Entity>;
67
+ /**
68
+ * Creates a single entity.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const todoItem = await this.service.createOne({title: 'Todo Item', completed: false });
73
+ * ```
74
+ * @param record - The entity to create.
75
+ */
76
+ createOne(record: DeepPartial<Entity>): Promise<Entity>;
77
+ /**
78
+ * Create multiple entities.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * const todoItem = await this.service.createMany([
83
+ * {title: 'Todo Item 1', completed: false },
84
+ * {title: 'Todo Item 2', completed: true },
85
+ * ]);
86
+ * ```
87
+ * @param records - The entities to create.
88
+ */
89
+ createMany(records: DeepPartial<Entity>[]): Promise<Entity[]>;
90
+ /**
91
+ * Update an entity.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * const updatedEntity = await this.service.updateOne(1, { completed: true });
96
+ * ```
97
+ * @param id - The `id` of the record.
98
+ * @param update - A `Partial` of the entity with fields to update.
99
+ * @param opts - Additional options
100
+ */
101
+ updateOne(id: string, update: DeepPartial<Entity>, opts?: UpdateOneOptions<Entity>): Promise<Entity>;
102
+ /**
103
+ * Update multiple entities with a `@ptc-org/nestjs-query-core` Filter.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const { updatedCount } = await this.service.updateMany(
108
+ * { completed: true }, // the update to apply
109
+ * { title: { eq: 'Foo Title' } } // Filter to find records to update
110
+ * );
111
+ * ```
112
+ * @param update - A `Partial` of entity with the fields to update
113
+ * @param filter - A Filter used to find the records to update
114
+ */
115
+ updateMany(update: DeepPartial<Entity>, filter: Filter<Entity>): Promise<UpdateManyResponse>;
116
+ /**
117
+ * Delete an entity by `id`.
118
+ *
119
+ * @example
120
+ *
121
+ * ```ts
122
+ * const deletedTodo = await this.service.deleteOne(1);
123
+ * ```
124
+ *
125
+ * @param id - The `id` of the entity to delete.
126
+ * @param opts - Additional filter to use when finding the entity to delete.
127
+ */
128
+ deleteOne(id: string, opts?: DeleteOneOptions<Entity>): Promise<Entity>;
129
+ /**
130
+ * Delete multiple records with a `@ptc-org/nestjs-query-core` `Filter`.
131
+ *
132
+ * @example
133
+ *
134
+ * ```ts
135
+ * const { deletedCount } = this.service.deleteMany({
136
+ * created: { lte: new Date('2020-1-1') }
137
+ * });
138
+ * ```
139
+ *
140
+ * @param filter - A `Filter` to find records to delete.
141
+ */
142
+ deleteMany(filter: Filter<Entity>): Promise<DeleteManyResponse>;
143
+ private ensureIdIsNotPresent;
144
+ private getUpdateQuery;
145
+ }
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongooseQueryService = void 0;
4
+ /* eslint-disable no-underscore-dangle */
5
+ const common_1 = require("@nestjs/common");
6
+ const query_1 = require("../query");
7
+ const reference_query_service_1 = require("./reference-query.service");
8
+ /**
9
+ * Base class for all query services that use Typegoose.
10
+ *
11
+ * @example
12
+ *
13
+ * ```ts
14
+ * @QueryService(TodoItemEntity)
15
+ * export class TodoItemService extends TypegooseQueryService<TodoItemEntity> {
16
+ * constructor(
17
+ * @InjectModel(TodoItemEntity) model: ReturnModelType<typeof TodoItemEntity>,
18
+ * ) {
19
+ * super(model);
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ class MongooseQueryService extends reference_query_service_1.ReferenceQueryService {
25
+ constructor(Model, filterQueryBuilder = new query_1.FilterQueryBuilder(Model)) {
26
+ super();
27
+ this.Model = Model;
28
+ this.filterQueryBuilder = filterQueryBuilder;
29
+ }
30
+ /**
31
+ * Query for multiple entities, using a Query from `@ptc-org/nestjs-query-core`.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const todoItems = await this.service.query({
36
+ * filter: { title: { eq: 'Foo' } },
37
+ * paging: { limit: 10 },
38
+ * sorting: [{ field: "create", direction: SortDirection.DESC }],
39
+ * });
40
+ * ```
41
+ * @param query - The Query used to filter, page, and sort rows.
42
+ */
43
+ async query(query) {
44
+ const { filterQuery, options } = this.filterQueryBuilder.buildQuery(query);
45
+ return this.Model.find(filterQuery, {}, options).exec();
46
+ }
47
+ async aggregate(filter, aggregateQuery) {
48
+ const { aggregate, filterQuery, options } = this.filterQueryBuilder.buildAggregateQuery(aggregateQuery, filter);
49
+ const aggPipeline = [{ $match: filterQuery }, { $group: aggregate }];
50
+ if (options.sort) {
51
+ aggPipeline.push({ $sort: options.sort ?? {} });
52
+ }
53
+ const aggResult = await this.Model.aggregate(aggPipeline).exec();
54
+ return query_1.AggregateBuilder.convertToAggregateResponse(aggResult);
55
+ }
56
+ count(filter) {
57
+ const filterQuery = this.filterQueryBuilder.buildFilterQuery(filter);
58
+ return this.Model.count(filterQuery).exec();
59
+ }
60
+ /**
61
+ * Find an entity by it's `id`.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const todoItem = await this.service.findById(1);
66
+ * ```
67
+ * @param id - The id of the record to find.
68
+ * @param opts - Additional options
69
+ */
70
+ async findById(id, opts) {
71
+ const filterQuery = this.filterQueryBuilder.buildIdFilterQuery(id, opts?.filter);
72
+ const doc = await this.Model.findOne(filterQuery);
73
+ if (!doc) {
74
+ return undefined;
75
+ }
76
+ return doc;
77
+ }
78
+ /**
79
+ * Gets an entity by it's `id`. If the entity is not found a rejected promise is returned.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * try {
84
+ * const todoItem = await this.service.getById(1);
85
+ * } catch(e) {
86
+ * console.error('Unable to find entity with id = 1');
87
+ * }
88
+ * ```
89
+ * @param id - The id of the record to find.
90
+ * @param opts - Additional options
91
+ */
92
+ async getById(id, opts) {
93
+ const doc = await this.findById(id, opts);
94
+ if (!doc) {
95
+ throw new common_1.NotFoundException(`Unable to find ${this.Model.modelName} with id: ${id}`);
96
+ }
97
+ return doc;
98
+ }
99
+ /**
100
+ * Creates a single entity.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const todoItem = await this.service.createOne({title: 'Todo Item', completed: false });
105
+ * ```
106
+ * @param record - The entity to create.
107
+ */
108
+ async createOne(record) {
109
+ this.ensureIdIsNotPresent(record);
110
+ return this.Model.create(record);
111
+ }
112
+ /**
113
+ * Create multiple entities.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const todoItem = await this.service.createMany([
118
+ * {title: 'Todo Item 1', completed: false },
119
+ * {title: 'Todo Item 2', completed: true },
120
+ * ]);
121
+ * ```
122
+ * @param records - The entities to create.
123
+ */
124
+ async createMany(records) {
125
+ records.forEach((r) => this.ensureIdIsNotPresent(r));
126
+ return this.Model.create(records);
127
+ }
128
+ /**
129
+ * Update an entity.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * const updatedEntity = await this.service.updateOne(1, { completed: true });
134
+ * ```
135
+ * @param id - The `id` of the record.
136
+ * @param update - A `Partial` of the entity with fields to update.
137
+ * @param opts - Additional options
138
+ */
139
+ async updateOne(id, update, opts) {
140
+ this.ensureIdIsNotPresent(update);
141
+ const filterQuery = this.filterQueryBuilder.buildIdFilterQuery(id, opts?.filter);
142
+ const doc = await this.Model.findOneAndUpdate(filterQuery, this.getUpdateQuery(update), {
143
+ new: true
144
+ });
145
+ if (!doc) {
146
+ throw new common_1.NotFoundException(`Unable to find ${this.Model.modelName} with id: ${id}`);
147
+ }
148
+ return doc;
149
+ }
150
+ /**
151
+ * Update multiple entities with a `@ptc-org/nestjs-query-core` Filter.
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * const { updatedCount } = await this.service.updateMany(
156
+ * { completed: true }, // the update to apply
157
+ * { title: { eq: 'Foo Title' } } // Filter to find records to update
158
+ * );
159
+ * ```
160
+ * @param update - A `Partial` of entity with the fields to update
161
+ * @param filter - A Filter used to find the records to update
162
+ */
163
+ async updateMany(update, filter) {
164
+ this.ensureIdIsNotPresent(update);
165
+ const filterQuery = this.filterQueryBuilder.buildFilterQuery(filter);
166
+ const res = await this.Model.updateMany(filterQuery, this.getUpdateQuery(update)).exec();
167
+ return { updatedCount: res.modifiedCount || 0 };
168
+ }
169
+ /**
170
+ * Delete an entity by `id`.
171
+ *
172
+ * @example
173
+ *
174
+ * ```ts
175
+ * const deletedTodo = await this.service.deleteOne(1);
176
+ * ```
177
+ *
178
+ * @param id - The `id` of the entity to delete.
179
+ * @param opts - Additional filter to use when finding the entity to delete.
180
+ */
181
+ async deleteOne(id, opts) {
182
+ const filterQuery = this.filterQueryBuilder.buildIdFilterQuery(id, opts?.filter);
183
+ const doc = await this.Model.findOneAndDelete(filterQuery);
184
+ if (!doc) {
185
+ throw new common_1.NotFoundException(`Unable to find ${this.Model.modelName} with id: ${id}`);
186
+ }
187
+ return doc;
188
+ }
189
+ /**
190
+ * Delete multiple records with a `@ptc-org/nestjs-query-core` `Filter`.
191
+ *
192
+ * @example
193
+ *
194
+ * ```ts
195
+ * const { deletedCount } = this.service.deleteMany({
196
+ * created: { lte: new Date('2020-1-1') }
197
+ * });
198
+ * ```
199
+ *
200
+ * @param filter - A `Filter` to find records to delete.
201
+ */
202
+ async deleteMany(filter) {
203
+ const filterQuery = this.filterQueryBuilder.buildFilterQuery(filter);
204
+ const res = (await this.Model.deleteMany(filterQuery).exec());
205
+ return { deletedCount: res.deletedCount || 0 };
206
+ }
207
+ ensureIdIsNotPresent(e) {
208
+ if (Object.keys(e).find((f) => f === 'id' || f === '_id')) {
209
+ throw new Error('Id cannot be specified when updating or creating');
210
+ }
211
+ }
212
+ getUpdateQuery(entity) {
213
+ if (entity instanceof this.Model) {
214
+ return entity.modifiedPaths().reduce((update, k) =>
215
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
216
+ ({ ...update, [k]: entity.get(k) }), {});
217
+ }
218
+ return entity;
219
+ }
220
+ }
221
+ exports.MongooseQueryService = MongooseQueryService;
222
+ //# sourceMappingURL=mongoose-query.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose-query.service.js","sourceRoot":"","sources":["../../../../../packages/query-mongoose/src/services/mongoose-query.service.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,2CAAkD;AAiBlD,oCAA+D;AAC/D,uEAAiE;AAUjE;;;;;;;;;;;;;;;GAeG;AACH,MAAa,oBACX,SAAQ,+CAA6B;IAGrC,YACW,KAA4B,EAC5B,qBAAiD,IAAI,0BAAkB,CAAC,KAAK,CAAC;QAEvF,KAAK,EAAE,CAAA;QAHE,UAAK,GAAL,KAAK,CAAuB;QAC5B,uBAAkB,GAAlB,kBAAk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;;;;;;;;OAYG;IACH,KAAK,CAAC,UAAU,CAAC,MAAsB;QACrC,MAAM,WAAW,GAAG,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QACpE,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,CAAyB,CAAA;QACrF,OAAO,EAAE,YAAY,EAAE,GAAG,CAAC,YAAY,IAAI,CAAC,EAAE,CAAA;IAChD,CAAC;IAEO,oBAAoB,CAAC,CAAsB;QACjD,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC,EAAE;YACzD,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;SACpE;IACH,CAAC;IAEO,cAAc,CAAC,MAA2B;QAChD,IAAI,MAAM,YAAY,IAAI,CAAC,KAAK,EAAE;YAChC,OAAO,MAAM,CAAC,aAAa,EAAE,CAAC,MAAM,CAClC,CAAC,MAA2B,EAAE,CAAC,EAAE,EAAE;YACjC,mEAAmE;YACnE,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EACrC,EAAE,CACH,CAAA;SACF;QACD,OAAO,MAA6B,CAAA;IACtC,CAAC;CACF;AA3ND,oDA2NC"}
@@ -0,0 +1,28 @@
1
+ import { AggregateQuery, AggregateResponse, Class, Filter, FindRelationOptions, GetByIdOptions, ModifyRelationOptions, Query } from '@ptc-org/nestjs-query-core';
2
+ import { Document, Model as MongooseModel } from 'mongoose';
3
+ export declare abstract class ReferenceQueryService<Entity extends Document> {
4
+ abstract readonly Model: MongooseModel<Entity>;
5
+ abstract getById(id: string | number, opts?: GetByIdOptions<Entity>): Promise<Entity>;
6
+ aggregateRelations<Relation extends Document>(RelationClass: Class<Relation>, relationName: string, entities: Entity[], filter: Filter<Relation>, aggregate: AggregateQuery<Relation>): Promise<Map<Entity, AggregateResponse<Relation>[]>>;
7
+ aggregateRelations<Relation extends Document>(RelationClass: Class<Relation>, relationName: string, dto: Entity, filter: Filter<Relation>, aggregate: AggregateQuery<Relation>): Promise<AggregateResponse<Relation>[]>;
8
+ countRelations<Relation extends Document>(RelationClass: Class<Relation>, relationName: string, entities: Entity[], filter: Filter<Relation>): Promise<Map<Entity, number>>;
9
+ countRelations<Relation extends Document>(RelationClass: Class<Relation>, relationName: string, dto: Entity, filter: Filter<Relation>): Promise<number>;
10
+ findRelation<Relation>(RelationClass: Class<Relation>, relationName: string, dtos: Entity[], opts?: FindRelationOptions<Relation>): Promise<Map<Entity, Relation | undefined>>;
11
+ findRelation<Relation>(RelationClass: Class<Relation>, relationName: string, dto: Entity, opts?: FindRelationOptions<Relation>): Promise<Relation | undefined>;
12
+ queryRelations<Relation>(RelationClass: Class<Relation>, relationName: string, entities: Entity[], query: Query<Relation>): Promise<Map<Entity, Relation[]>>;
13
+ queryRelations<Relation>(RelationClass: Class<Relation>, relationName: string, dto: Entity, query: Query<Relation>): Promise<Relation[]>;
14
+ addRelations<Relation extends Document>(relationName: string, id: string, relationIds: (string | number)[], opts?: ModifyRelationOptions<Entity, Relation>): Promise<Entity>;
15
+ setRelations<Relation extends Document>(relationName: string, id: string, relationIds: (string | number)[], opts?: ModifyRelationOptions<Entity, Relation>): Promise<Entity>;
16
+ setRelation<Relation extends Document>(relationName: string, id: string | number, relationId: string | number, opts?: ModifyRelationOptions<Entity, Relation>): Promise<Entity>;
17
+ removeRelation<Relation extends Document>(relationName: string, id: string | number, relationId: string | number, opts?: ModifyRelationOptions<Entity, Relation>): Promise<Entity>;
18
+ removeRelations<Relation extends Document>(relationName: string, id: string | number, relationIds: string[] | number[], opts?: ModifyRelationOptions<Entity, Relation>): Promise<Entity>;
19
+ private checkForReference;
20
+ private isReferencePath;
21
+ private isVirtualPath;
22
+ private getReferenceQueryBuilder;
23
+ private getReferenceModel;
24
+ private getReferenceFilter;
25
+ private getObjectIdReferenceFilter;
26
+ private getVirtualReferenceFilter;
27
+ private getRefCount;
28
+ }