@uecsio/utils-api 0.0.1

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 ADDED
@@ -0,0 +1,24 @@
1
+ # @uecsio/utils
2
+
3
+ Shared TypeScript utility helpers used across UECS services.
4
+
5
+ ## Scripts
6
+
7
+ - `pnpm run build` – compile TypeScript to `dist/`
8
+ - `pnpm run lint` – run ESLint on the source
9
+ - `pnpm run test` – execute unit tests with Jest
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { compactObject } from '@uecsio/utils';
15
+
16
+ const cleaned = compactObject({
17
+ id: 1,
18
+ name: 'Example',
19
+ optional: undefined,
20
+ });
21
+
22
+ console.log(cleaned); // { id: 1, name: 'Example' }
23
+ ```
24
+
@@ -0,0 +1,6 @@
1
+ export * from './services/url-generator.service';
2
+ export { BaseTypeOrmCrudService } from './services/base-typeorm-crud.service';
3
+ export { IsUrlPath } from './validators/is-url-path.validator';
4
+ export { IsUniqueValue } from './validators/is-unique-value.validator';
5
+ export { IsUniqueValueConstraint } from './validators/is-unique-value.constraint';
6
+ export type { UniqueValueConstraintOptions } from './validators/is-unique-value.constraint';
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.IsUniqueValueConstraint = exports.IsUniqueValue = exports.IsUrlPath = exports.BaseTypeOrmCrudService = void 0;
18
+ __exportStar(require("./services/url-generator.service"), exports);
19
+ var base_typeorm_crud_service_1 = require("./services/base-typeorm-crud.service");
20
+ Object.defineProperty(exports, "BaseTypeOrmCrudService", { enumerable: true, get: function () { return base_typeorm_crud_service_1.BaseTypeOrmCrudService; } });
21
+ var is_url_path_validator_1 = require("./validators/is-url-path.validator");
22
+ Object.defineProperty(exports, "IsUrlPath", { enumerable: true, get: function () { return is_url_path_validator_1.IsUrlPath; } });
23
+ var is_unique_value_validator_1 = require("./validators/is-unique-value.validator");
24
+ Object.defineProperty(exports, "IsUniqueValue", { enumerable: true, get: function () { return is_unique_value_validator_1.IsUniqueValue; } });
25
+ var is_unique_value_constraint_1 = require("./validators/is-unique-value.constraint");
26
+ Object.defineProperty(exports, "IsUniqueValueConstraint", { enumerable: true, get: function () { return is_unique_value_constraint_1.IsUniqueValueConstraint; } });
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mEAAiD;AACjD,kFAA8E;AAArE,mIAAA,sBAAsB,OAAA;AAC/B,4EAA+D;AAAtD,kHAAA,SAAS,OAAA;AAClB,oFAAuE;AAA9D,0HAAA,aAAa,OAAA;AACtB,sFAAkF;AAAzE,qIAAA,uBAAuB,OAAA"}
@@ -0,0 +1,5 @@
1
+ import { TypeOrmCrudService } from '@dataui/crud-typeorm';
2
+ import { Repository, ObjectLiteral } from 'typeorm';
3
+ export declare abstract class BaseTypeOrmCrudService<T extends ObjectLiteral> extends TypeOrmCrudService<T> {
4
+ getRepository(): Repository<T>;
5
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.BaseTypeOrmCrudService = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const crud_typeorm_1 = require("@dataui/crud-typeorm");
12
+ let BaseTypeOrmCrudService = class BaseTypeOrmCrudService extends crud_typeorm_1.TypeOrmCrudService {
13
+ getRepository() {
14
+ return this.repo;
15
+ }
16
+ };
17
+ exports.BaseTypeOrmCrudService = BaseTypeOrmCrudService;
18
+ exports.BaseTypeOrmCrudService = BaseTypeOrmCrudService = __decorate([
19
+ (0, common_1.Injectable)()
20
+ ], BaseTypeOrmCrudService);
21
+ //# sourceMappingURL=base-typeorm-crud.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-typeorm-crud.service.js","sourceRoot":"","sources":["../../src/services/base-typeorm-crud.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,uDAA0D;AAwBnD,IAAe,sBAAsB,GAArC,MAAe,sBAAgD,SAAQ,iCAAqB;IAKjG,aAAa;QACX,OAAQ,IAAY,CAAC,IAAI,CAAC;IAC5B,CAAC;CACF,CAAA;AARqB,wDAAsB;iCAAtB,sBAAsB;IAD3C,IAAA,mBAAU,GAAE;GACS,sBAAsB,CAQ3C"}
@@ -0,0 +1,13 @@
1
+ import type { FindOptionsWhere, ObjectLiteral, Repository } from 'typeorm';
2
+ export type FindableRepository<TEntity extends ObjectLiteral> = Pick<Repository<TEntity>, 'findOne'>;
3
+ export type GenerateUrlOptions<TEntity extends ObjectLiteral> = {
4
+ extraCondition?: FindOptionsWhere<TEntity>;
5
+ excludeId?: number | string;
6
+ maxAttempts?: number;
7
+ };
8
+ export declare class UrlGeneratorService {
9
+ generateUrl<TEntity extends ObjectLiteral>(urlField: string | undefined, baseValue: string, repository: FindableRepository<TEntity>, options?: GenerateUrlOptions<TEntity>): Promise<string>;
10
+ private createSlug;
11
+ private buildWhere;
12
+ private incrementUrlIndex;
13
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.UrlGeneratorService = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const translit_rus_eng_1 = require("translit-rus-eng");
12
+ const typeorm_1 = require("typeorm");
13
+ const DEFAULT_MAX_ATTEMPTS = 100;
14
+ const DEFAULT_URL_FIELD = 'url';
15
+ let UrlGeneratorService = class UrlGeneratorService {
16
+ async generateUrl(urlField = DEFAULT_URL_FIELD, baseValue, repository, options = {}) {
17
+ var _a;
18
+ if (!(baseValue === null || baseValue === void 0 ? void 0 : baseValue.trim())) {
19
+ throw new Error('Base value is required to generate URL');
20
+ }
21
+ let candidate = this.createSlug(baseValue);
22
+ const maxAttempts = (_a = options.maxAttempts) !== null && _a !== void 0 ? _a : DEFAULT_MAX_ATTEMPTS;
23
+ for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
24
+ const where = this.buildWhere(urlField, candidate, options.extraCondition, options.excludeId);
25
+ const findOptions = { where };
26
+ const existing = await repository.findOne(findOptions);
27
+ if (!existing) {
28
+ return candidate;
29
+ }
30
+ candidate = this.incrementUrlIndex(candidate);
31
+ }
32
+ throw new Error('Unable to generate a unique URL after maximum attempts');
33
+ }
34
+ createSlug(value) {
35
+ const transliterated = (0, translit_rus_eng_1.default)(value, { slug: true });
36
+ return transliterated.toLowerCase().replace(/_/g, '-');
37
+ }
38
+ buildWhere(urlField, candidate, extraCondition, excludeId) {
39
+ const baseCondition = (extraCondition !== null && extraCondition !== void 0 ? extraCondition : {});
40
+ const where = {
41
+ ...baseCondition,
42
+ [urlField]: candidate,
43
+ };
44
+ if (excludeId !== undefined) {
45
+ where.id = (0, typeorm_1.Not)(excludeId);
46
+ }
47
+ return where;
48
+ }
49
+ incrementUrlIndex(url) {
50
+ const parts = url.split('-');
51
+ const last = parts[parts.length - 1];
52
+ const numeric = Number.parseInt(last, 10);
53
+ if (Number.isNaN(numeric)) {
54
+ return `${url}-1`;
55
+ }
56
+ parts[parts.length - 1] = String(numeric + 1);
57
+ return parts.join('-');
58
+ }
59
+ };
60
+ exports.UrlGeneratorService = UrlGeneratorService;
61
+ exports.UrlGeneratorService = UrlGeneratorService = __decorate([
62
+ (0, common_1.Injectable)()
63
+ ], UrlGeneratorService);
64
+ //# sourceMappingURL=url-generator.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-generator.service.js","sourceRoot":"","sources":["../../src/services/url-generator.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,uDAA6C;AAE7C,qCAA8B;AAa9B,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAGzB,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAM9B,KAAK,CAAC,WAAW,CACf,WAAmB,iBAAiB,EACpC,SAAiB,EACjB,UAAuC,EACvC,UAAuC,EAAE;;QAEzC,IAAI,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,EAAE,CAAA,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC5D,CAAC;QAED,IAAI,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAC3C,MAAM,WAAW,GAAG,MAAA,OAAO,CAAC,WAAW,mCAAI,oBAAoB,CAAC;QAEhE,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,WAAW,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC;YAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;YAC9F,MAAM,WAAW,GAAG,EAAE,KAAK,EAA6B,CAAC;YACzD,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAEvD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,SAAS,GAAG,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IAGO,UAAU,CAAC,KAAa;QAC9B,MAAM,cAAc,GAAG,IAAA,0BAAa,EAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5D,OAAO,cAAc,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACzD,CAAC;IAGO,UAAU,CAChB,QAAgB,EAChB,SAAiB,EACjB,cAAqD,EACrD,SAA2B;QAE3B,MAAM,aAAa,GAAG,CAAC,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,EAAE,CAA8B,CAAC;QAC1E,MAAM,KAAK,GAA8B;YACvC,GAAG,aAAa;YAChB,CAAC,QAAQ,CAAC,EAAE,SAAS;SACO,CAAC;QAG/B,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC3B,KAAa,CAAC,EAAE,GAAG,IAAA,aAAG,EAAC,SAAS,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAGO,iBAAiB,CAAC,GAAW;QACnC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACrC,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAE1C,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1B,OAAO,GAAG,GAAG,IAAI,CAAC;QACpB,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;QAC9C,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;CACF,CAAA;AA1EY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;GACA,mBAAmB,CA0E/B"}
@@ -0,0 +1,13 @@
1
+ import { ValidatorConstraintInterface, ValidationArguments } from 'class-validator';
2
+ import { DataSource, ObjectLiteral, EntityTarget } from 'typeorm';
3
+ export interface UniqueValueConstraintOptions {
4
+ entity: EntityTarget<ObjectLiteral>;
5
+ field: string;
6
+ idField?: string;
7
+ }
8
+ export declare class IsUniqueValueConstraint implements ValidatorConstraintInterface {
9
+ private readonly dataSource;
10
+ constructor(dataSource: DataSource);
11
+ validate(value: any, args: ValidationArguments): Promise<boolean>;
12
+ defaultMessage(args: ValidationArguments): string;
13
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.IsUniqueValueConstraint = void 0;
16
+ const class_validator_1 = require("class-validator");
17
+ const common_1 = require("@nestjs/common");
18
+ const typeorm_1 = require("@nestjs/typeorm");
19
+ const typeorm_2 = require("typeorm");
20
+ let IsUniqueValueConstraint = class IsUniqueValueConstraint {
21
+ constructor(dataSource) {
22
+ this.dataSource = dataSource;
23
+ }
24
+ async validate(value, args) {
25
+ if (value === null || value === undefined) {
26
+ return true;
27
+ }
28
+ const options = args.constraints[0];
29
+ if (!options || !options.entity || !options.field) {
30
+ return false;
31
+ }
32
+ const object = args.object;
33
+ const repository = this.dataSource.getRepository(options.entity);
34
+ const tableName = repository.metadata.tableName;
35
+ const alias = 'entity';
36
+ const queryBuilder = repository
37
+ .createQueryBuilder(alias)
38
+ .where(`${alias}.${options.field} = :value`, { value });
39
+ const idField = options.idField || 'id';
40
+ const excludeId = object[idField] || object['id'];
41
+ if (excludeId !== null && excludeId !== undefined) {
42
+ queryBuilder.andWhere(`${alias}.${idField} != :excludeId`, { excludeId });
43
+ }
44
+ const existing = await queryBuilder.getOne();
45
+ return !existing;
46
+ }
47
+ defaultMessage(args) {
48
+ const options = args.constraints[0];
49
+ const fieldName = (options === null || options === void 0 ? void 0 : options.field) || 'value';
50
+ return `${fieldName} must be unique`;
51
+ }
52
+ };
53
+ exports.IsUniqueValueConstraint = IsUniqueValueConstraint;
54
+ exports.IsUniqueValueConstraint = IsUniqueValueConstraint = __decorate([
55
+ (0, class_validator_1.ValidatorConstraint)({ name: 'isUniqueValue', async: true }),
56
+ (0, common_1.Injectable)(),
57
+ __param(0, (0, typeorm_1.InjectDataSource)()),
58
+ __metadata("design:paramtypes", [typeorm_2.DataSource])
59
+ ], IsUniqueValueConstraint);
60
+ //# sourceMappingURL=is-unique-value.constraint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-unique-value.constraint.js","sourceRoot":"","sources":["../../src/validators/is-unique-value.constraint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qDAIyB;AACzB,2CAA4C;AAC5C,6CAAmD;AACnD,qCAAkE;AAU3D,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAClC,YAAiD,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAE3E,KAAK,CAAC,QAAQ,CAAC,KAAU,EAAE,IAAyB;QAElD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;QAGD,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAiC,CAAC;QACpE,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAClD,OAAO,KAAK,CAAC;QACf,CAAC;QAGD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAa,CAAC;QAGlC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAGjE,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC;QAChD,MAAM,KAAK,GAAG,QAAQ,CAAC;QAGvB,MAAM,YAAY,GAAG,UAAU;aAC5B,kBAAkB,CAAC,KAAK,CAAC;aACzB,KAAK,CAAC,GAAG,KAAK,IAAI,OAAO,CAAC,KAAK,WAAW,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAG1D,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC;QACxC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;QAElD,IAAI,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAClD,YAAY,CAAC,QAAQ,CAAC,GAAG,KAAK,IAAI,OAAO,gBAAgB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;QAC5E,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,CAAC;QAE7C,OAAO,CAAC,QAAQ,CAAC;IACnB,CAAC;IAED,cAAc,CAAC,IAAyB;QACtC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAiC,CAAC;QACpE,MAAM,SAAS,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,KAAI,OAAO,CAAC;QAC5C,OAAO,GAAG,SAAS,iBAAiB,CAAC;IACvC,CAAC;CACF,CAAA;AAhDY,0DAAuB;kCAAvB,uBAAuB;IAFnC,IAAA,qCAAmB,EAAC,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC3D,IAAA,mBAAU,GAAE;IAEE,WAAA,IAAA,0BAAgB,GAAE,CAAA;qCAA8B,oBAAU;GAD5D,uBAAuB,CAgDnC"}
@@ -0,0 +1,3 @@
1
+ import { ValidationOptions } from 'class-validator';
2
+ import { EntityTarget, ObjectLiteral } from 'typeorm';
3
+ export declare function IsUniqueValue(entity: EntityTarget<ObjectLiteral>, field: string, idField?: string, validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsUniqueValue = IsUniqueValue;
4
+ const class_validator_1 = require("class-validator");
5
+ const is_unique_value_constraint_1 = require("./is-unique-value.constraint");
6
+ function IsUniqueValue(entity, field, idField, validationOptions) {
7
+ return function (object, propertyName) {
8
+ const options = {
9
+ entity,
10
+ field,
11
+ idField,
12
+ };
13
+ (0, class_validator_1.registerDecorator)({
14
+ name: 'isUniqueValue',
15
+ target: object.constructor,
16
+ propertyName: propertyName,
17
+ options: validationOptions,
18
+ constraints: [options],
19
+ validator: is_unique_value_constraint_1.IsUniqueValueConstraint,
20
+ });
21
+ };
22
+ }
23
+ //# sourceMappingURL=is-unique-value.validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-unique-value.validator.js","sourceRoot":"","sources":["../../src/validators/is-unique-value.validator.ts"],"names":[],"mappings":";;AAyCA,sCAsBC;AA/DD,qDAIyB;AAEzB,6EAAqG;AAmCrG,SAAgB,aAAa,CAC3B,MAAmC,EACnC,KAAa,EACb,OAAgB,EAChB,iBAAqC;IAErC,OAAO,UAAU,MAAc,EAAE,YAAoB;QACnD,MAAM,OAAO,GAAiC;YAC5C,MAAM;YACN,KAAK;YACL,OAAO;SACR,CAAC;QAEF,IAAA,mCAAiB,EAAC;YAChB,IAAI,EAAE,eAAe;YACrB,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,OAAO,EAAE,iBAAiB;YAC1B,WAAW,EAAE,CAAC,OAAO,CAAC;YACtB,SAAS,EAAE,oDAAuB;SACnC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { ValidationOptions } from 'class-validator';
2
+ export declare function IsUrlPath(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsUrlPath = IsUrlPath;
4
+ const class_validator_1 = require("class-validator");
5
+ function IsUrlPath(validationOptions) {
6
+ return function (object, propertyName) {
7
+ (0, class_validator_1.registerDecorator)({
8
+ name: 'isUrlPath',
9
+ target: object.constructor,
10
+ propertyName: propertyName,
11
+ options: validationOptions,
12
+ validator: {
13
+ validate(value, args) {
14
+ if (typeof value !== 'string') {
15
+ return false;
16
+ }
17
+ const urlPathRegex = /^[a-zA-Z0-9\-_\/.]+$/;
18
+ return urlPathRegex.test(value);
19
+ },
20
+ defaultMessage(args) {
21
+ return 'URL path can only contain alphanumeric characters, hyphens, underscores, forward slashes, and periods';
22
+ },
23
+ },
24
+ });
25
+ };
26
+ }
27
+ //# sourceMappingURL=is-url-path.validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-url-path.validator.js","sourceRoot":"","sources":["../../src/validators/is-url-path.validator.ts"],"names":[],"mappings":";;AAqBA,8BAsBC;AA3CD,qDAIyB;AAiBzB,SAAgB,SAAS,CAAC,iBAAqC;IAC7D,OAAO,UAAU,MAAc,EAAE,YAAoB;QACnD,IAAA,mCAAiB,EAAC;YAChB,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,OAAO,EAAE,iBAAiB;YAC1B,SAAS,EAAE;gBACT,QAAQ,CAAC,KAAU,EAAE,IAAyB;oBAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;wBAC9B,OAAO,KAAK,CAAC;oBACf,CAAC;oBAED,MAAM,YAAY,GAAG,sBAAsB,CAAC;oBAC5C,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAClC,CAAC;gBACD,cAAc,CAAC,IAAyB;oBACtC,OAAO,uGAAuG,CAAC;gBACjH,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@uecsio/utils-api",
3
+ "version": "0.0.1",
4
+ "description": "Shared utility helpers for UECS API services.",
5
+ "author": "Dmytro Morozov <morozovdmitry@gmail.com>",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "files": [
10
+ "dist/**/*"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "build:watch": "tsc --watch",
15
+ "lint": "eslint src/**/*.ts",
16
+ "lint:fix": "eslint src/**/*.ts --fix",
17
+ "test": "jest",
18
+ "test:watch": "jest --watch",
19
+ "test:cov": "jest --coverage",
20
+ "clean": "rimraf dist"
21
+ },
22
+ "dependencies": {
23
+ "@nestjs/common": "^11.1.6",
24
+ "translit-rus-eng": "^2.0.0"
25
+ },
26
+ "peerDependencies": {
27
+ "typeorm": "^0.3.26",
28
+ "class-validator": "^0.14.0",
29
+ "@nestjs/typeorm": "^11.0.0",
30
+ "@dataui/crud-typeorm": "^5.3.4"
31
+ },
32
+ "devDependencies": {
33
+ "@types/jest": "^30.0.0",
34
+ "@types/node": "^22.10.7",
35
+ "jest": "^30.0.0",
36
+ "rimraf": "^5.0.0",
37
+ "ts-jest": "^29.2.5",
38
+ "typescript": "^5.7.3"
39
+ },
40
+ "jest": {
41
+ "moduleFileExtensions": [
42
+ "js",
43
+ "json",
44
+ "ts"
45
+ ],
46
+ "rootDir": "src",
47
+ "testRegex": ".*\\.spec\\.ts$",
48
+ "transform": {
49
+ "^.+\\.(t|j)s$": "ts-jest"
50
+ },
51
+ "collectCoverageFrom": [
52
+ "**/*.(t|j)s"
53
+ ],
54
+ "coverageDirectory": "../coverage",
55
+ "testEnvironment": "node"
56
+ }
57
+ }
58
+