itlab-internal-services 2.4.2 → 2.4.4
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/create-duplicate-checker.function.d.ts +3 -0
- package/dist/create-duplicate-checker.function.js +29 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/models/filter/limit.property.js +2 -1
- package/dist/models/filter/skip.property.js +2 -6
- package/dist/models/filter/sort-direction.property.js +8 -6
- package/dist/models/filter/sort-field.property.js +2 -4
- package/dist/models/search-result.d.ts +4 -2
- package/dist/models/search-result.js +22 -3
- package/dist/modules/search/index.d.ts +1 -1
- package/dist/modules/search/index.js +2 -1
- package/dist/modules/search/search.models.d.ts +7 -0
- package/dist/modules/search/search.models.js +25 -1
- package/dist/modules/search/search.service.d.ts +8 -1
- package/dist/modules/search/search.service.js +22 -0
- package/dist/pipes/hid.pipe.js +1 -8
- package/dist/pipes/target.pipe.js +1 -8
- package/dist/transform/castToArray.d.ts +5 -0
- package/dist/transform/castToArray.js +12 -0
- package/dist/transform/index.d.ts +4 -0
- package/dist/transform/index.js +9 -1
- package/dist/transform/transformBoolean.d.ts +5 -0
- package/dist/transform/transformBoolean.js +22 -0
- package/dist/transform/transformNumber.d.ts +14 -0
- package/dist/transform/transformNumber.js +23 -0
- package/dist/transform/transformTimestamp.d.ts +16 -0
- package/dist/transform/transformTimestamp.js +31 -0
- package/package.json +1 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Document, Model } from 'mongoose';
|
|
2
|
+
import { ErrorException } from './exceptions';
|
|
3
|
+
export declare function createDuplicateChecker<D, T extends Document>(model: Model<T>, criticalKeys: (keyof D & keyof T)[], error?: new () => ErrorException): (dto: D, target?: T) => Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createDuplicateChecker = void 0;
|
|
13
|
+
const exceptions_1 = require("./exceptions");
|
|
14
|
+
function createDuplicateChecker(model, criticalKeys, error = exceptions_1.DuplicateException) {
|
|
15
|
+
return (dto, target) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const fq = {};
|
|
17
|
+
for (const key of criticalKeys) {
|
|
18
|
+
if (dto && key in dto)
|
|
19
|
+
fq[key] = dto[key];
|
|
20
|
+
if (target && key in target)
|
|
21
|
+
fq[key] = target[key];
|
|
22
|
+
}
|
|
23
|
+
const found = yield model.findOne(fq);
|
|
24
|
+
const compareId = target ? String(target._id).toLowerCase() : undefined;
|
|
25
|
+
if (found && String(found._id).toLowerCase() !== compareId)
|
|
26
|
+
throw new error();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.createDuplicateChecker = createDuplicateChecker;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./create-duplicate-checker.function"), exports);
|
|
17
18
|
__exportStar(require("./exceptions"), exports);
|
|
18
19
|
__exportStar(require("./favicon.controller"), exports);
|
|
19
20
|
__exportStar(require("./guards"), exports);
|
|
@@ -4,8 +4,9 @@ exports.PropertyLimit = void 0;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
6
|
const class_validator_1 = require("class-validator");
|
|
7
|
+
const transform_1 = require("../../transform");
|
|
7
8
|
/**
|
|
8
9
|
* Creates a PropertyLimitDecorator with the given options.
|
|
9
10
|
*/
|
|
10
|
-
const PropertyLimit = () => (0, common_1.applyDecorators)((0, swagger_1.
|
|
11
|
+
const PropertyLimit = () => (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({ minimum: 0, default: 10, description: 'Die maximale Anzahl der Ergebnisse' }), (0, transform_1.TransformNumber)({ default: 10, min: 0 }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.Min)(0));
|
|
11
12
|
exports.PropertyLimit = PropertyLimit;
|
|
@@ -4,13 +4,9 @@ exports.PropertySkip = void 0;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
6
|
const class_validator_1 = require("class-validator");
|
|
7
|
+
const transform_1 = require("../../transform");
|
|
7
8
|
/**
|
|
8
9
|
* Creates a PropertySkipDecorator with the given options.
|
|
9
10
|
*/
|
|
10
|
-
const PropertySkip = () => (0, common_1.applyDecorators)((0, swagger_1.
|
|
11
|
-
required: false,
|
|
12
|
-
minimum: 0,
|
|
13
|
-
example: 0,
|
|
14
|
-
description: 'Die Anzahl der zu überspringenden Ergebnisse',
|
|
15
|
-
}), (0, class_validator_1.IsOptional)(), (0, class_validator_1.Min)(0));
|
|
11
|
+
const PropertySkip = () => (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({ minimum: 0, default: 0, description: 'Die Anzahl der zu überspringenden Ergebnisse' }), (0, transform_1.TransformNumber)({ default: 0, min: 0 }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.Min)(0));
|
|
16
12
|
exports.PropertySkip = PropertySkip;
|
|
@@ -4,13 +4,15 @@ exports.PropertySortDirection = void 0;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
6
|
const class_validator_1 = require("class-validator");
|
|
7
|
+
const transform_1 = require("../../transform");
|
|
7
8
|
/**
|
|
8
9
|
* Creates a PropertySortDirectionDecorator with the given options.
|
|
9
10
|
*/
|
|
10
|
-
const PropertySortDirection = () => (0, common_1.applyDecorators)((0, swagger_1.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
11
|
+
const PropertySortDirection = () => (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({
|
|
12
|
+
description: 'Die Reihenfolge der Ergebnisse (1 = aufsteigend, -1 = absteigend [default])',
|
|
13
|
+
examples: {
|
|
14
|
+
asc: { value: 1, summary: 'Aufsteigend' },
|
|
15
|
+
desc: { value: -1, summary: 'Absteigend (Standard)' },
|
|
16
|
+
},
|
|
17
|
+
}), (0, transform_1.TransformNumber)({ default: -1, min: -1, max: 1 }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.IsIn)([-1, 1]));
|
|
16
18
|
exports.PropertySortDirection = PropertySortDirection;
|
|
@@ -7,11 +7,9 @@ const class_validator_1 = require("class-validator");
|
|
|
7
7
|
/**
|
|
8
8
|
* Creates a PropertySortFieldDecorator with the given options.
|
|
9
9
|
*/
|
|
10
|
-
const PropertySortField = () => (0, common_1.applyDecorators)((0, swagger_1.
|
|
11
|
-
required: false,
|
|
10
|
+
const PropertySortField = () => (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({
|
|
12
11
|
description: 'Das Feld, nach dem sortiert werden soll',
|
|
13
|
-
examples: ['title', 'timestamp', 'createdAt', 'updatedAt', '_id'],
|
|
14
|
-
example: 'title',
|
|
15
12
|
default: '_id',
|
|
13
|
+
example: 'title',
|
|
16
14
|
}), (0, class_validator_1.IsOptional)(), (0, class_validator_1.MinLength)(1));
|
|
17
15
|
exports.PropertySortField = PropertySortField;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
1
2
|
/**
|
|
2
3
|
* Represents the result of a search operation.
|
|
3
4
|
*
|
|
@@ -6,9 +7,10 @@
|
|
|
6
7
|
* @property {T[]} results - Array of found objects.
|
|
7
8
|
* @property {number} total - Total number of objects without pagination.
|
|
8
9
|
*/
|
|
9
|
-
export declare class SearchResult<
|
|
10
|
+
export declare class SearchResult<TData> {
|
|
10
11
|
/** Array of found objects. */
|
|
11
|
-
results:
|
|
12
|
+
results: TData[];
|
|
12
13
|
/** Total number of objects without pagination. */
|
|
13
14
|
total: number;
|
|
14
15
|
}
|
|
16
|
+
export declare const ApiSearchResultResponse: <TModel extends Type<any>>(model: TModel) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -9,7 +9,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.SearchResult = void 0;
|
|
12
|
+
exports.ApiSearchResultResponse = exports.SearchResult = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
13
14
|
const swagger_1 = require("@nestjs/swagger");
|
|
14
15
|
/**
|
|
15
16
|
* Represents the result of a search operation.
|
|
@@ -22,11 +23,29 @@ const swagger_1 = require("@nestjs/swagger");
|
|
|
22
23
|
class SearchResult {
|
|
23
24
|
}
|
|
24
25
|
__decorate([
|
|
25
|
-
(0, swagger_1.ApiProperty)({ description: 'Gefundene
|
|
26
|
+
(0, swagger_1.ApiProperty)({ description: 'Gefundene Elemente', type: [Object] }),
|
|
26
27
|
__metadata("design:type", Array)
|
|
27
28
|
], SearchResult.prototype, "results", void 0);
|
|
28
29
|
__decorate([
|
|
29
|
-
(0, swagger_1.ApiProperty)({ description: 'Insgesamt
|
|
30
|
+
(0, swagger_1.ApiProperty)({ description: 'Insgesamt verfügbare Elemente', example: 17 }),
|
|
30
31
|
__metadata("design:type", Number)
|
|
31
32
|
], SearchResult.prototype, "total", void 0);
|
|
32
33
|
exports.SearchResult = SearchResult;
|
|
34
|
+
const ApiSearchResultResponse = (model) => (0, common_1.applyDecorators)((0, swagger_1.ApiExtraModels)(SearchResult, model), (0, swagger_1.ApiOkResponse)({
|
|
35
|
+
description: 'Gefundene Elemente',
|
|
36
|
+
schema: {
|
|
37
|
+
title: `SearchResultOf${model.name}`,
|
|
38
|
+
allOf: [
|
|
39
|
+
{ $ref: (0, swagger_1.getSchemaPath)(SearchResult) },
|
|
40
|
+
{
|
|
41
|
+
properties: {
|
|
42
|
+
results: {
|
|
43
|
+
type: 'array',
|
|
44
|
+
items: { $ref: (0, swagger_1.getSchemaPath)(model) },
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
}));
|
|
51
|
+
exports.ApiSearchResultResponse = ApiSearchResultResponse;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SearchService = exports.SearchModule = exports.SearchableDocument = void 0;
|
|
3
|
+
exports.SearchService = exports.SearchModule = exports.SearchDocument = exports.SearchableDocument = void 0;
|
|
4
4
|
var search_models_1 = require("./search.models");
|
|
5
5
|
Object.defineProperty(exports, "SearchableDocument", { enumerable: true, get: function () { return search_models_1.SearchableDocument; } });
|
|
6
|
+
Object.defineProperty(exports, "SearchDocument", { enumerable: true, get: function () { return search_models_1.SearchDocument; } });
|
|
6
7
|
var search_module_1 = require("./search.module");
|
|
7
8
|
Object.defineProperty(exports, "SearchModule", { enumerable: true, get: function () { return search_module_1.SearchModule; } });
|
|
8
9
|
var search_service_1 = require("./search.service");
|
|
@@ -9,8 +9,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.SearchableDocument = void 0;
|
|
12
|
+
exports.SearchDocument = exports.SearchableDocument = void 0;
|
|
13
13
|
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
const pipes_1 = require("../../pipes");
|
|
14
15
|
/**
|
|
15
16
|
* Represents a searchable document.
|
|
16
17
|
*
|
|
@@ -39,3 +40,26 @@ __decorate([
|
|
|
39
40
|
__metadata("design:type", Object)
|
|
40
41
|
], SearchableDocument.prototype, "data", void 0);
|
|
41
42
|
exports.SearchableDocument = SearchableDocument;
|
|
43
|
+
class SearchDocument {
|
|
44
|
+
}
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, swagger_1.ApiProperty)({ description: 'Id des Ergebnisses' }),
|
|
47
|
+
__metadata("design:type", String)
|
|
48
|
+
], SearchDocument.prototype, "id", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, swagger_1.ApiProperty)({ description: 'Typ des Ergebnisses', enum: pipes_1.Targets }),
|
|
51
|
+
__metadata("design:type", String)
|
|
52
|
+
], SearchDocument.prototype, "type", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, swagger_1.ApiProperty)({ description: 'Anzeigename des Ergebnisses' }),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], SearchDocument.prototype, "label", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, swagger_1.ApiProperty)({ description: 'Link zum Ergebnis' }),
|
|
59
|
+
__metadata("design:type", String)
|
|
60
|
+
], SearchDocument.prototype, "url", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, swagger_1.ApiProperty)({ description: 'Anzeigename des Ergebnisses mit Highlights (<mark>)' }),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], SearchDocument.prototype, "highlight", void 0);
|
|
65
|
+
exports.SearchDocument = SearchDocument;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigService } from '@nestjs/config';
|
|
2
2
|
import { Targets } from '../../pipes';
|
|
3
|
-
import { SearchableDocument } from './search.models';
|
|
3
|
+
import { SearchableDocument, SearchDocument } from './search.models';
|
|
4
4
|
/**
|
|
5
5
|
* Search service
|
|
6
6
|
* @class SearchService
|
|
@@ -32,4 +32,11 @@ export declare class SearchService {
|
|
|
32
32
|
* @return {void}
|
|
33
33
|
*/
|
|
34
34
|
remove(targetId: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Find similar documents from elasticsaech
|
|
37
|
+
*
|
|
38
|
+
* @param {string} targetId - the ID of the target to find similar documents of
|
|
39
|
+
* @returns {Promise<SearchDocument[]>} Promise containing similar documents
|
|
40
|
+
*/
|
|
41
|
+
similar(targetId: string): Promise<SearchDocument[]>;
|
|
35
42
|
}
|
|
@@ -11,6 +11,15 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
14
23
|
var SearchService_1;
|
|
15
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
25
|
exports.SearchService = void 0;
|
|
@@ -66,6 +75,19 @@ let SearchService = SearchService_1 = class SearchService {
|
|
|
66
75
|
.then(() => this.logger.log(`Sucessfully removed ${this.target} (${targetId})`))
|
|
67
76
|
.catch(({ response }) => this.logger.error(`Couldn't remove ${this.target} (${targetId})`, response.data));
|
|
68
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Find similar documents from elasticsaech
|
|
80
|
+
*
|
|
81
|
+
* @param {string} targetId - the ID of the target to find similar documents of
|
|
82
|
+
* @returns {Promise<SearchDocument[]>} Promise containing similar documents
|
|
83
|
+
*/
|
|
84
|
+
similar(targetId) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
this.logger.log(`Finding similar documents for ${this.target} (${targetId})`);
|
|
87
|
+
const response = yield this.axios.get(`${this.target}/${targetId}/similar`);
|
|
88
|
+
return response.data;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
69
91
|
};
|
|
70
92
|
SearchService = SearchService_1 = __decorate([
|
|
71
93
|
(0, common_1.Injectable)(),
|
package/dist/pipes/hid.pipe.js
CHANGED
|
@@ -58,14 +58,7 @@ exports.Hid = Hid;
|
|
|
58
58
|
* @param {string} param - the parameter for the API HID
|
|
59
59
|
* @return A decorator that creates an API HID with the given parameter
|
|
60
60
|
*/
|
|
61
|
-
const ApiHid = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)({
|
|
62
|
-
name: param,
|
|
63
|
-
example: 'hallo-welt',
|
|
64
|
-
examples: {
|
|
65
|
-
'Hallo Welt': { value: 'hallo-welt' },
|
|
66
|
-
'Heute ist ein toller Tag': { value: 'heute-ist-ein-toller-tag' },
|
|
67
|
-
},
|
|
68
|
-
}), (0, swagger_1.ApiResponse)({ description, status }));
|
|
61
|
+
const ApiHid = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)({ name: param, example: 'hallo-welt' }), (0, swagger_1.ApiResponse)({ description, status }));
|
|
69
62
|
exports.ApiHid = ApiHid;
|
|
70
63
|
/**
|
|
71
64
|
* Check if the given value is a valid hub ID.
|
|
@@ -79,12 +79,5 @@ exports.Target = Target;
|
|
|
79
79
|
* @param {string} param - the parameter for the API target
|
|
80
80
|
* @return A decorator that creates an API target with the given parameter
|
|
81
81
|
*/
|
|
82
|
-
const ApiTarget = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)({
|
|
83
|
-
name: param,
|
|
84
|
-
example: Targets.NEWSROOM,
|
|
85
|
-
examples: Object.entries(Targets).reduce((map, [value, key]) => {
|
|
86
|
-
map[key] = { value };
|
|
87
|
-
return map;
|
|
88
|
-
}, {}),
|
|
89
|
-
}), (0, swagger_1.ApiResponse)({ description, status }));
|
|
82
|
+
const ApiTarget = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)({ name: param, enum: Targets }), (0, swagger_1.ApiResponse)({ description, status }));
|
|
90
83
|
exports.ApiTarget = ApiTarget;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CastToArray = void 0;
|
|
4
|
+
const class_transformer_1 = require("class-transformer");
|
|
5
|
+
/**
|
|
6
|
+
* This function casts the input value to an array if it's not an
|
|
7
|
+
* array, otherwise it returns the original value.
|
|
8
|
+
*/
|
|
9
|
+
function CastToArray() {
|
|
10
|
+
return (0, class_transformer_1.Transform)(({ value }) => (Array.isArray(value) ? value : [value]));
|
|
11
|
+
}
|
|
12
|
+
exports.CastToArray = CastToArray;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
export { CastToArray } from './castToArray';
|
|
2
|
+
export { TransformBoolean } from './transformBoolean';
|
|
1
3
|
export { TransformImage } from './transformImage';
|
|
4
|
+
export { TransformNumber } from './transformNumber';
|
|
2
5
|
export { TransformString } from './transformString';
|
|
3
6
|
export { TransformStringArray } from './transformStringArray';
|
|
4
7
|
export { isStringLike, isStringLikeMin, TransformStringLike } from './transformStringLike';
|
|
5
8
|
export { TransformStringLowerCase } from './transformStringLowerCase';
|
|
6
9
|
export { TransformStringSet } from './transformStringSet';
|
|
10
|
+
export { TransformTimestamp } from './transformTimestamp';
|
package/dist/transform/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TransformStringSet = exports.TransformStringLowerCase = exports.TransformStringLike = exports.isStringLikeMin = exports.isStringLike = exports.TransformStringArray = exports.TransformString = exports.TransformImage = void 0;
|
|
3
|
+
exports.TransformTimestamp = exports.TransformStringSet = exports.TransformStringLowerCase = exports.TransformStringLike = exports.isStringLikeMin = exports.isStringLike = exports.TransformStringArray = exports.TransformString = exports.TransformNumber = exports.TransformImage = exports.TransformBoolean = exports.CastToArray = void 0;
|
|
4
|
+
var castToArray_1 = require("./castToArray");
|
|
5
|
+
Object.defineProperty(exports, "CastToArray", { enumerable: true, get: function () { return castToArray_1.CastToArray; } });
|
|
6
|
+
var transformBoolean_1 = require("./transformBoolean");
|
|
7
|
+
Object.defineProperty(exports, "TransformBoolean", { enumerable: true, get: function () { return transformBoolean_1.TransformBoolean; } });
|
|
4
8
|
var transformImage_1 = require("./transformImage");
|
|
5
9
|
Object.defineProperty(exports, "TransformImage", { enumerable: true, get: function () { return transformImage_1.TransformImage; } });
|
|
10
|
+
var transformNumber_1 = require("./transformNumber");
|
|
11
|
+
Object.defineProperty(exports, "TransformNumber", { enumerable: true, get: function () { return transformNumber_1.TransformNumber; } });
|
|
6
12
|
var transformString_1 = require("./transformString");
|
|
7
13
|
Object.defineProperty(exports, "TransformString", { enumerable: true, get: function () { return transformString_1.TransformString; } });
|
|
8
14
|
var transformStringArray_1 = require("./transformStringArray");
|
|
@@ -15,3 +21,5 @@ var transformStringLowerCase_1 = require("./transformStringLowerCase");
|
|
|
15
21
|
Object.defineProperty(exports, "TransformStringLowerCase", { enumerable: true, get: function () { return transformStringLowerCase_1.TransformStringLowerCase; } });
|
|
16
22
|
var transformStringSet_1 = require("./transformStringSet");
|
|
17
23
|
Object.defineProperty(exports, "TransformStringSet", { enumerable: true, get: function () { return transformStringSet_1.TransformStringSet; } });
|
|
24
|
+
var transformTimestamp_1 = require("./transformTimestamp");
|
|
25
|
+
Object.defineProperty(exports, "TransformTimestamp", { enumerable: true, get: function () { return transformTimestamp_1.TransformTimestamp; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransformBoolean = void 0;
|
|
4
|
+
const class_transformer_1 = require("class-transformer");
|
|
5
|
+
const transformStringLike_1 = require("./transformStringLike");
|
|
6
|
+
const _trim_1 = require("./_trim");
|
|
7
|
+
/**
|
|
8
|
+
* This function transforms the input value to a trimmed number if it's a string
|
|
9
|
+
* or a number, otherwise it returns the original value.
|
|
10
|
+
*/
|
|
11
|
+
function TransformBoolean() {
|
|
12
|
+
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
13
|
+
if ((0, transformStringLike_1.isStringLike)(value))
|
|
14
|
+
value = (0, _trim_1.trimStringLike)(value).toLowerCase();
|
|
15
|
+
if (value === true || value === 'true' || value === 1 || value === '1')
|
|
16
|
+
return true;
|
|
17
|
+
if (value === false || value === 'false' || value === 0 || value === '0')
|
|
18
|
+
return false;
|
|
19
|
+
return value;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.TransformBoolean = TransformBoolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface NumberOptions {
|
|
2
|
+
/** Default value if value isnt a number */
|
|
3
|
+
default?: number;
|
|
4
|
+
/** Maximum value */
|
|
5
|
+
min?: number;
|
|
6
|
+
/** Minimum value */
|
|
7
|
+
max?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* This function transforms the input value to a trimmed number if it's a string
|
|
11
|
+
* or a number, otherwise it returns the original value.
|
|
12
|
+
*/
|
|
13
|
+
export declare function TransformNumber(opts?: NumberOptions): PropertyDecorator;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransformNumber = void 0;
|
|
4
|
+
const class_transformer_1 = require("class-transformer");
|
|
5
|
+
/**
|
|
6
|
+
* This function transforms the input value to a trimmed number if it's a string
|
|
7
|
+
* or a number, otherwise it returns the original value.
|
|
8
|
+
*/
|
|
9
|
+
function TransformNumber(opts = {}) {
|
|
10
|
+
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
11
|
+
let number = Number.parseInt(value || String(opts.default), 10);
|
|
12
|
+
if (Number.isNaN(number) && !opts.default)
|
|
13
|
+
return value;
|
|
14
|
+
if (Number.isNaN(number))
|
|
15
|
+
number = opts.default;
|
|
16
|
+
if (opts.min && number < opts.min)
|
|
17
|
+
number = opts.min;
|
|
18
|
+
if (opts.max && number > opts.max)
|
|
19
|
+
number = opts.max;
|
|
20
|
+
return number;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.TransformNumber = TransformNumber;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface NumberOptions {
|
|
2
|
+
/** Default value if value isnt a number */
|
|
3
|
+
default?: number;
|
|
4
|
+
/** Maximum value */
|
|
5
|
+
min?: number;
|
|
6
|
+
/** Minimum value */
|
|
7
|
+
max?: number;
|
|
8
|
+
/** Round the timestamp to the nearest <unit> */
|
|
9
|
+
roundTo?: 'ms' | 's' | 'm' | 'h';
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* This function transforms the input value to a trimmed number if it's a string
|
|
13
|
+
* or a number, otherwise it returns the original value.
|
|
14
|
+
*/
|
|
15
|
+
export declare function TransformTimestamp(opts?: NumberOptions): PropertyDecorator;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransformTimestamp = void 0;
|
|
4
|
+
const class_transformer_1 = require("class-transformer");
|
|
5
|
+
/**
|
|
6
|
+
* This function transforms the input value to a trimmed number if it's a string
|
|
7
|
+
* or a number, otherwise it returns the original value.
|
|
8
|
+
*/
|
|
9
|
+
function TransformTimestamp(opts = {}) {
|
|
10
|
+
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
11
|
+
let number = Number.parseInt(value || String(opts.default), 10);
|
|
12
|
+
if (Number.isNaN(number) && !opts.default)
|
|
13
|
+
return value;
|
|
14
|
+
if (Number.isNaN(number))
|
|
15
|
+
number = opts.default;
|
|
16
|
+
if (opts.min && number < opts.min)
|
|
17
|
+
number = opts.min;
|
|
18
|
+
if (opts.max && number > opts.max)
|
|
19
|
+
number = opts.max;
|
|
20
|
+
if (opts.roundTo === 'h')
|
|
21
|
+
return new Date(number).setHours(0, 0, 0, 0);
|
|
22
|
+
if (opts.roundTo === 'm')
|
|
23
|
+
return new Date(number).setMinutes(0, 0, 0);
|
|
24
|
+
if (opts.roundTo === 's')
|
|
25
|
+
return new Date(number).setSeconds(0, 0);
|
|
26
|
+
if (opts.roundTo === 'ms')
|
|
27
|
+
return new Date(number).setMilliseconds(0);
|
|
28
|
+
return number;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.TransformTimestamp = TransformTimestamp;
|