itlab-internal-services 2.16.16 → 2.16.18
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/dist/classes/document/timestamps-document.class.js +2 -2
- package/dist/classes/fetch-options/base-options.class.js +10 -9
- package/dist/classes/fetch-options/index.d.ts +2 -0
- package/dist/classes/fetch-options/index.js +2 -0
- package/dist/classes/fetch-options/optional-filter.class.d.ts +43 -0
- package/dist/classes/fetch-options/optional-filter.class.js +52 -0
- package/dist/classes/fetch-options/optional-time-range-filter.class.d.ts +37 -0
- package/dist/classes/fetch-options/optional-time-range-filter.class.js +48 -0
- package/dist/modules/services/base-http.service.js +9 -11
- package/package.json +1 -1
|
@@ -17,12 +17,12 @@ function TimestampsDocument(Base) {
|
|
|
17
17
|
}
|
|
18
18
|
__decorate([
|
|
19
19
|
(0, swagger_1.ApiPropertyOptional)({ description: 'Date the item was created at' }),
|
|
20
|
-
(0, mongoose_1.Prop)({ type: Date
|
|
20
|
+
(0, mongoose_1.Prop)({ type: Date }),
|
|
21
21
|
__metadata("design:type", Date)
|
|
22
22
|
], TimestampsDocument.prototype, "createdAt", void 0);
|
|
23
23
|
__decorate([
|
|
24
24
|
(0, swagger_1.ApiPropertyOptional)({ description: 'Date the item was last updated at' }),
|
|
25
|
-
(0, mongoose_1.Prop)({ type: Date
|
|
25
|
+
(0, mongoose_1.Prop)({ type: Date }),
|
|
26
26
|
__metadata("design:type", Date)
|
|
27
27
|
], TimestampsDocument.prototype, "updatedAt", void 0);
|
|
28
28
|
return TimestampsDocument;
|
|
@@ -14,6 +14,7 @@ exports.parseBaseOptions = parseBaseOptions;
|
|
|
14
14
|
const swagger_1 = require("@nestjs/swagger");
|
|
15
15
|
const class_validator_1 = require("class-validator");
|
|
16
16
|
const transform_1 = require("../../transform");
|
|
17
|
+
const optional_filter_class_1 = require("./optional-filter.class");
|
|
17
18
|
class BaseOptions {
|
|
18
19
|
}
|
|
19
20
|
exports.BaseOptions = BaseOptions;
|
|
@@ -81,18 +82,18 @@ __decorate([
|
|
|
81
82
|
__metadata("design:type", Number)
|
|
82
83
|
], BaseOptions.prototype, "limit", void 0);
|
|
83
84
|
function parseBaseOptions(options, filterQuery, queryOptions) {
|
|
84
|
-
var _a, _b, _c, _d, _e
|
|
85
|
+
var _a, _b, _c, _d, _e;
|
|
85
86
|
// Handle IDs: Combine single and multiple document IDs into a single $in filter.
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
filterQuery._id = { $in:
|
|
87
|
+
const idFilter = new optional_filter_class_1.OptionalFilter(options.id, options.ids);
|
|
88
|
+
if (idFilter.isActive)
|
|
89
|
+
filterQuery._id = { $in: idFilter.values };
|
|
89
90
|
// Sorting: Default sort by _id descending unless overridden in filterQuery.
|
|
90
|
-
const sortField = (
|
|
91
|
-
const sortDirection = (
|
|
92
|
-
(
|
|
91
|
+
const sortField = (_a = options.sortField) !== null && _a !== void 0 ? _a : '_id';
|
|
92
|
+
const sortDirection = (_b = options.sortDirection) !== null && _b !== void 0 ? _b : -1;
|
|
93
|
+
(_c = queryOptions.sort) !== null && _c !== void 0 ? _c : (queryOptions.sort = { [sortField]: sortDirection });
|
|
93
94
|
// Pagination: Respect limit and skip if explicitly set in filterQuery.
|
|
94
95
|
if (options.limit !== undefined)
|
|
95
|
-
(
|
|
96
|
+
(_d = queryOptions.limit) !== null && _d !== void 0 ? _d : (queryOptions.limit = options.limit);
|
|
96
97
|
if (options.skip !== undefined)
|
|
97
|
-
(
|
|
98
|
+
(_e = queryOptions.skip) !== null && _e !== void 0 ? _e : (queryOptions.skip = options.skip);
|
|
98
99
|
}
|
|
@@ -3,5 +3,7 @@ export * from './comments-options.class';
|
|
|
3
3
|
export * from './content-options.class';
|
|
4
4
|
export * from './drafted-options.class';
|
|
5
5
|
export * from './liked-by-options.class';
|
|
6
|
+
export * from './optional-filter.class';
|
|
7
|
+
export * from './optional-time-range-filter.class';
|
|
6
8
|
export * from './timestamps-options.class';
|
|
7
9
|
export * from './viewed-by-options.class';
|
|
@@ -19,5 +19,7 @@ __exportStar(require("./comments-options.class"), exports);
|
|
|
19
19
|
__exportStar(require("./content-options.class"), exports);
|
|
20
20
|
__exportStar(require("./drafted-options.class"), exports);
|
|
21
21
|
__exportStar(require("./liked-by-options.class"), exports);
|
|
22
|
+
__exportStar(require("./optional-filter.class"), exports);
|
|
23
|
+
__exportStar(require("./optional-time-range-filter.class"), exports);
|
|
22
24
|
__exportStar(require("./timestamps-options.class"), exports);
|
|
23
25
|
__exportStar(require("./viewed-by-options.class"), exports);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an optional filter that may be provided as either a single value
|
|
3
|
+
* or multiple values. Normalizes all inputs into a deduplicated array for
|
|
4
|
+
* consistent downstream query usage.
|
|
5
|
+
*
|
|
6
|
+
* This abstraction separates filter presence from stored values, allowing
|
|
7
|
+
* consumers to detect whether filtering logic should be applied at all.
|
|
8
|
+
*/
|
|
9
|
+
export declare class OptionalFilter<T> {
|
|
10
|
+
private readonly singleValue;
|
|
11
|
+
private readonly multipleValues;
|
|
12
|
+
/**
|
|
13
|
+
* Internal storage for deduplicated filter values.
|
|
14
|
+
*/
|
|
15
|
+
private readonly valueSet;
|
|
16
|
+
/**
|
|
17
|
+
* Creates an optional filter from either a single value or an array of values.
|
|
18
|
+
*
|
|
19
|
+
* @param singleValue - Optional single filter value.
|
|
20
|
+
* @param multipleValues - Optional array of filter values.
|
|
21
|
+
*/
|
|
22
|
+
constructor(singleValue: T | undefined, multipleValues: T[] | undefined);
|
|
23
|
+
/**
|
|
24
|
+
* Whether this filter was explicitly provided by the caller.
|
|
25
|
+
*
|
|
26
|
+
* True if at least one value was supplied, even if the array is empty.
|
|
27
|
+
*/
|
|
28
|
+
get isActive(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Returns all deduplicated filter values as an array.
|
|
31
|
+
*
|
|
32
|
+
* Downstream logic can use this to build queries without worrying about
|
|
33
|
+
* whether the original input was a single value or multiple values.
|
|
34
|
+
*/
|
|
35
|
+
get values(): T[];
|
|
36
|
+
/**
|
|
37
|
+
* Checks whether a specific value is included in this filter.
|
|
38
|
+
*
|
|
39
|
+
* @param value - The value to test for inclusion.
|
|
40
|
+
* @returns True if the value is present in the filter.
|
|
41
|
+
*/
|
|
42
|
+
contains(value: T): boolean;
|
|
43
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OptionalFilter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Represents an optional filter that may be provided as either a single value
|
|
6
|
+
* or multiple values. Normalizes all inputs into a deduplicated array for
|
|
7
|
+
* consistent downstream query usage.
|
|
8
|
+
*
|
|
9
|
+
* This abstraction separates filter presence from stored values, allowing
|
|
10
|
+
* consumers to detect whether filtering logic should be applied at all.
|
|
11
|
+
*/
|
|
12
|
+
class OptionalFilter {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an optional filter from either a single value or an array of values.
|
|
15
|
+
*
|
|
16
|
+
* @param singleValue - Optional single filter value.
|
|
17
|
+
* @param multipleValues - Optional array of filter values.
|
|
18
|
+
*/
|
|
19
|
+
constructor(singleValue, multipleValues) {
|
|
20
|
+
this.singleValue = singleValue;
|
|
21
|
+
this.multipleValues = multipleValues;
|
|
22
|
+
// Normalize both inputs into a single iterable; deduplicate via Set
|
|
23
|
+
this.valueSet = new Set([...(singleValue !== undefined ? [singleValue] : []), ...(multipleValues !== null && multipleValues !== void 0 ? multipleValues : [])]);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether this filter was explicitly provided by the caller.
|
|
27
|
+
*
|
|
28
|
+
* True if at least one value was supplied, even if the array is empty.
|
|
29
|
+
*/
|
|
30
|
+
get isActive() {
|
|
31
|
+
return this.singleValue !== undefined || this.multipleValues !== undefined;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns all deduplicated filter values as an array.
|
|
35
|
+
*
|
|
36
|
+
* Downstream logic can use this to build queries without worrying about
|
|
37
|
+
* whether the original input was a single value or multiple values.
|
|
38
|
+
*/
|
|
39
|
+
get values() {
|
|
40
|
+
return Array.from(this.valueSet);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Checks whether a specific value is included in this filter.
|
|
44
|
+
*
|
|
45
|
+
* @param value - The value to test for inclusion.
|
|
46
|
+
* @returns True if the value is present in the filter.
|
|
47
|
+
*/
|
|
48
|
+
contains(value) {
|
|
49
|
+
return this.valueSet.has(value);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.OptionalFilter = OptionalFilter;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an optional timestamp range filter that may or may not be
|
|
3
|
+
* provided by the caller.
|
|
4
|
+
*
|
|
5
|
+
* This abstraction separates filter presence from filter content, allowing
|
|
6
|
+
* query-building logic to reliably determine whether a range constraint
|
|
7
|
+
* should be applied.
|
|
8
|
+
*/
|
|
9
|
+
export declare class OptionalTimeRangeFilter {
|
|
10
|
+
private readonly minTimestamp;
|
|
11
|
+
private readonly maxTimestamp;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an optional timestamp range filter.
|
|
14
|
+
*
|
|
15
|
+
* @param minTimestamp - Optional lower bound (inclusive).
|
|
16
|
+
* @param maxTimestamp - Optional upper bound (inclusive).
|
|
17
|
+
*/
|
|
18
|
+
constructor(minTimestamp: number | undefined, maxTimestamp: number | undefined);
|
|
19
|
+
/**
|
|
20
|
+
* Whether this filter was explicitly provided by the caller.
|
|
21
|
+
*
|
|
22
|
+
* @returns True if at least one bound is defined.
|
|
23
|
+
*/
|
|
24
|
+
get isActive(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The MongoDB-compatible range query for this filter.
|
|
27
|
+
*
|
|
28
|
+
* Only defined bounds are included to avoid unintentionally constraining
|
|
29
|
+
* the query.
|
|
30
|
+
*
|
|
31
|
+
* @returns A range query object suitable for use in a filter expression.
|
|
32
|
+
*/
|
|
33
|
+
get query(): {
|
|
34
|
+
$gte?: number;
|
|
35
|
+
$lte?: number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OptionalTimeRangeFilter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Represents an optional timestamp range filter that may or may not be
|
|
6
|
+
* provided by the caller.
|
|
7
|
+
*
|
|
8
|
+
* This abstraction separates filter presence from filter content, allowing
|
|
9
|
+
* query-building logic to reliably determine whether a range constraint
|
|
10
|
+
* should be applied.
|
|
11
|
+
*/
|
|
12
|
+
class OptionalTimeRangeFilter {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an optional timestamp range filter.
|
|
15
|
+
*
|
|
16
|
+
* @param minTimestamp - Optional lower bound (inclusive).
|
|
17
|
+
* @param maxTimestamp - Optional upper bound (inclusive).
|
|
18
|
+
*/
|
|
19
|
+
constructor(minTimestamp, maxTimestamp) {
|
|
20
|
+
this.minTimestamp = minTimestamp;
|
|
21
|
+
this.maxTimestamp = maxTimestamp;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Whether this filter was explicitly provided by the caller.
|
|
25
|
+
*
|
|
26
|
+
* @returns True if at least one bound is defined.
|
|
27
|
+
*/
|
|
28
|
+
get isActive() {
|
|
29
|
+
return this.minTimestamp !== undefined || this.maxTimestamp !== undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The MongoDB-compatible range query for this filter.
|
|
33
|
+
*
|
|
34
|
+
* Only defined bounds are included to avoid unintentionally constraining
|
|
35
|
+
* the query.
|
|
36
|
+
*
|
|
37
|
+
* @returns A range query object suitable for use in a filter expression.
|
|
38
|
+
*/
|
|
39
|
+
get query() {
|
|
40
|
+
const rangeQuery = {};
|
|
41
|
+
if (this.minTimestamp !== undefined)
|
|
42
|
+
rangeQuery.$gte = this.minTimestamp;
|
|
43
|
+
if (this.maxTimestamp !== undefined)
|
|
44
|
+
rangeQuery.$lte = this.maxTimestamp;
|
|
45
|
+
return rangeQuery;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.OptionalTimeRangeFilter = OptionalTimeRangeFilter;
|
|
@@ -110,18 +110,16 @@ class BaseHttpService {
|
|
|
110
110
|
async fetchResourceCollection(endpoint, config = {}) {
|
|
111
111
|
var _a;
|
|
112
112
|
const ids = (_a = config.params) === null || _a === void 0 ? void 0 : _a.ids;
|
|
113
|
-
if (
|
|
114
|
-
|
|
113
|
+
if (ids && Array.isArray(ids) && ids.length > 50) {
|
|
114
|
+
// Parallelize requests for each chunk; flatten the results into one array.
|
|
115
|
+
const batchPromises = (0, itlab_functions_1.createChunks)(ids, 50).map((chunk) => {
|
|
116
|
+
config.params.ids = chunk;
|
|
117
|
+
return this.fetchResourceCollectionBatch(endpoint, config);
|
|
118
|
+
});
|
|
119
|
+
const results = await Promise.all(batchPromises);
|
|
120
|
+
return results.flat();
|
|
115
121
|
}
|
|
116
|
-
|
|
117
|
-
const uniqueIds = Array.from(new Set(ids));
|
|
118
|
-
const idChunks = (0, itlab_functions_1.createChunks)(uniqueIds, 50);
|
|
119
|
-
// Parallelize requests for each chunk; flatten the results into one array.
|
|
120
|
-
const batchPromises = idChunks.map((chunk) => {
|
|
121
|
-
config.params.ids = chunk;
|
|
122
|
-
return this.fetchResourceCollectionBatch(endpoint, config);
|
|
123
|
-
});
|
|
124
|
-
return (await Promise.all(batchPromises)).flat();
|
|
122
|
+
return this.fetchResourceCollectionBatch(endpoint, config);
|
|
125
123
|
}
|
|
126
124
|
/**
|
|
127
125
|
* Helper for fetching a batch (or full collection) of resources in a single request.
|