@foxiko/nest-common 0.2.26 → 0.2.27

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.
@@ -0,0 +1,16 @@
1
+ import { EntityRepository, FilterQuery, FindOptions, RequiredEntityData, AnyEntity } from '@mikro-orm/core';
2
+ import { EventEmitter2 } from '@nestjs/event-emitter';
3
+ import { BaseService } from './base.service';
4
+ export declare abstract class BaseRelatedService<T extends AnyEntity, R extends AnyEntity> extends BaseService<T> {
5
+ protected readonly repository: EntityRepository<T>;
6
+ protected readonly relatedRepository: EntityRepository<R>;
7
+ protected readonly eventEmitter?: EventEmitter2;
8
+ slug: string;
9
+ protected constructor(repository: EntityRepository<T>, relatedRepository: EntityRepository<R>, eventEmitter?: EventEmitter2);
10
+ findAll(where: FilterQuery<T>, options?: FindOptions<T>): Promise<import("@mikro-orm/core").Loaded<T, never, import("@mikro-orm/core").PopulatePath.ALL, never>[]>;
11
+ query(where: FilterQuery<T>, options: FindOptions<T>): Promise<[import("@mikro-orm/core").Loaded<T, never, import("@mikro-orm/core").PopulatePath.ALL, never>[], number]>;
12
+ findOne(where: FilterQuery<T>): Promise<import("@mikro-orm/core").Loaded<T, never, "*", never>>;
13
+ create(data: RequiredEntityData<T>): Promise<T>;
14
+ createMany(data: RequiredEntityData<T>[]): Promise<T[]>;
15
+ private validateRelatedEntity;
16
+ }
@@ -0,0 +1,12 @@
1
+ export declare class CRUDEventUpdate<T> {
2
+ readonly entity: T;
3
+ constructor(entity: T);
4
+ }
5
+ export declare class CRUDEventCreate<T> {
6
+ readonly entity: T;
7
+ constructor(entity: T);
8
+ }
9
+ export declare class CRUDEventDelete<T> {
10
+ readonly entity: T;
11
+ constructor(entity: T);
12
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CRUDEventDelete = exports.CRUDEventCreate = exports.CRUDEventUpdate = void 0;
4
+ class CRUDEventUpdate {
5
+ constructor(entity) {
6
+ this.entity = entity;
7
+ }
8
+ }
9
+ exports.CRUDEventUpdate = CRUDEventUpdate;
10
+ class CRUDEventCreate {
11
+ constructor(entity) {
12
+ this.entity = entity;
13
+ }
14
+ }
15
+ exports.CRUDEventCreate = CRUDEventCreate;
16
+ class CRUDEventDelete {
17
+ constructor(entity) {
18
+ this.entity = entity;
19
+ }
20
+ }
21
+ exports.CRUDEventDelete = CRUDEventDelete;
22
+ //# sourceMappingURL=base.event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.event.js","sourceRoot":"","sources":["../../src/common/base.event.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAe;IACxB,YAA4B,MAAS;QAAT,WAAM,GAAN,MAAM,CAAG;IAAG,CAAC;CAC5C;AAFD,0CAEC;AAED,MAAa,eAAe;IACxB,YAA4B,MAAS;QAAT,WAAM,GAAN,MAAM,CAAG;IAAG,CAAC;CAC5C;AAFD,0CAEC;AAED,MAAa,eAAe;IACxB,YAA4B,MAAS;QAAT,WAAM,GAAN,MAAM,CAAG;IAAG,CAAC;CAC5C;AAFD,0CAEC"}
@@ -0,0 +1,16 @@
1
+ import { EntityRepository, FilterQuery, FindOptions, RequiredEntityData, EntityData, AnyEntity } from '@mikro-orm/core';
2
+ import { EventEmitter2 } from '@nestjs/event-emitter';
3
+ export declare abstract class BaseService<T extends AnyEntity> {
4
+ protected readonly repository: EntityRepository<T>;
5
+ protected readonly eventEmitter?: EventEmitter2;
6
+ slug: string;
7
+ protected constructor(repository: EntityRepository<T>, eventEmitter?: EventEmitter2);
8
+ findAll(where: FilterQuery<T>, options?: FindOptions<T>): Promise<import("@mikro-orm/core").Loaded<T, never, import("@mikro-orm/core").PopulatePath.ALL, never>[]>;
9
+ query(where: FilterQuery<T>, options: FindOptions<T>): Promise<[import("@mikro-orm/core").Loaded<T, never, import("@mikro-orm/core").PopulatePath.ALL, never>[], number]>;
10
+ count(where: FilterQuery<T>, options?: FindOptions<T>): Promise<number>;
11
+ findOne(where: FilterQuery<T>): Promise<import("@mikro-orm/core").Loaded<T, never, "*", never>>;
12
+ delete(where: FilterQuery<T>): Promise<number>;
13
+ create(data: RequiredEntityData<T>): Promise<T>;
14
+ createMany(data: RequiredEntityData<T>[]): Promise<T[]>;
15
+ update(where: FilterQuery<T>, data: EntityData<T>): Promise<import("@mikro-orm/core").Loaded<T, never, "*", never>>;
16
+ }
@@ -0,0 +1,2 @@
1
+ export declare const CRUD_OPTIONS_METADATA = "crud:options";
2
+ export declare const FETCHED_ENTITY_KEY = "crud:fetched_entity";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FETCHED_ENTITY_KEY = exports.CRUD_OPTIONS_METADATA = void 0;
4
+ exports.CRUD_OPTIONS_METADATA = 'crud:options';
5
+ exports.FETCHED_ENTITY_KEY = 'crud:fetched_entity';
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,cAAc,CAAC;AACvC,QAAA,kBAAkB,GAAG,qBAAqB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { EntityData, AnyEntity } from '@mikro-orm/core';
2
+ import { BaseService } from '../base.service';
3
+ import { CrudOptions } from '../interfaces/crud-options.interface';
4
+ export interface ICrudController<T extends AnyEntity> {
5
+ readonly service: BaseService<T>;
6
+ }
7
+ export declare function Crud<T extends AnyEntity, C = EntityData<T>, U = EntityData<T>>(options: CrudOptions<T, C, U>): (target: Function) => void;
@@ -0,0 +1,2 @@
1
+ import { Type } from '@nestjs/common';
2
+ export declare function Embedded(typeFunc?: () => Type<any>): PropertyDecorator;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Embedded = Embedded;
4
+ const swagger_1 = require("@nestjs/swagger");
5
+ const class_transformer_1 = require("class-transformer");
6
+ const EMBEDDED_METADATA_KEY = 'custom:embedded_properties';
7
+ const EMBEDDED_CLASS_KEY = 'custom:embedded_class';
8
+ function Embedded(typeFunc) {
9
+ return (target, propertyKey) => {
10
+ const properties = Reflect.getMetadata(EMBEDDED_METADATA_KEY, target) || [];
11
+ if (!properties.includes(propertyKey)) {
12
+ properties.push(propertyKey);
13
+ Reflect.defineMetadata(EMBEDDED_METADATA_KEY, properties, target);
14
+ }
15
+ (0, class_transformer_1.Exclude)()(target, propertyKey);
16
+ (0, swagger_1.ApiHideProperty)()(target, propertyKey);
17
+ const targetConstructor = target.constructor;
18
+ let EmbeddedClass = Reflect.getMetadata(EMBEDDED_CLASS_KEY, targetConstructor);
19
+ if (!EmbeddedClass) {
20
+ EmbeddedClass = class {
21
+ };
22
+ Object.defineProperty(EmbeddedClass, 'name', { value: `${targetConstructor.name}Embedded` });
23
+ Reflect.defineMetadata(EMBEDDED_CLASS_KEY, EmbeddedClass, targetConstructor);
24
+ Object.defineProperty(target, '_embedded', {
25
+ get: function () {
26
+ const embeddedProps = Reflect.getMetadata(EMBEDDED_METADATA_KEY, target) || [];
27
+ const result = {};
28
+ let hasValues = false;
29
+ for (const prop of embeddedProps) {
30
+ if (this[prop] !== undefined && this[prop] !== null) {
31
+ result[prop] = this[prop];
32
+ hasValues = true;
33
+ }
34
+ }
35
+ return hasValues ? result : undefined;
36
+ },
37
+ enumerable: true,
38
+ configurable: true,
39
+ });
40
+ (0, class_transformer_1.Expose)()(target, '_embedded');
41
+ (0, swagger_1.ApiProperty)({ type: EmbeddedClass, readOnly: true, required: true })(target, '_embedded');
42
+ (0, class_transformer_1.Type)(() => EmbeddedClass)(target, '_embedded');
43
+ }
44
+ const designType = Reflect.getMetadata('design:type', target, propertyKey);
45
+ const isArray = designType === Array;
46
+ const resolvedType = typeFunc ? typeFunc() : designType;
47
+ Object.defineProperty(EmbeddedClass.prototype, propertyKey, {
48
+ value: undefined,
49
+ writable: true,
50
+ enumerable: true,
51
+ configurable: true,
52
+ });
53
+ (0, class_transformer_1.Expose)()(EmbeddedClass.prototype, propertyKey);
54
+ if (isArray && resolvedType) {
55
+ (0, swagger_1.ApiProperty)({ type: resolvedType, isArray: true })(EmbeddedClass.prototype, propertyKey);
56
+ (0, class_transformer_1.Type)(() => resolvedType)(EmbeddedClass.prototype, propertyKey);
57
+ }
58
+ else if (resolvedType) {
59
+ (0, swagger_1.ApiProperty)({ type: resolvedType })(EmbeddedClass.prototype, propertyKey);
60
+ (0, class_transformer_1.Type)(() => resolvedType)(EmbeddedClass.prototype, propertyKey);
61
+ }
62
+ else {
63
+ (0, swagger_1.ApiProperty)()(EmbeddedClass.prototype, propertyKey);
64
+ }
65
+ };
66
+ }
67
+ //# sourceMappingURL=embedded.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedded.decorator.js","sourceRoot":"","sources":["../../../src/common/decorators/embedded.decorator.ts"],"names":[],"mappings":";;AAOA,4BAgFC;AAtFD,6CAA+D;AAC/D,yDAA2E;AAE3E,MAAM,qBAAqB,GAAG,4BAA4B,CAAC;AAC3D,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAEnD,SAAgB,QAAQ,CAAC,QAA0B;IACjD,OAAO,CAAC,MAAW,EAAE,WAA4B,EAAE,EAAE;QAEnD,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,qBAAqB,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5E,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YACtC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC7B,OAAO,CAAC,cAAc,CAAC,qBAAqB,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;QACpE,CAAC;QAGD,IAAA,2BAAO,GAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAC/B,IAAA,yBAAe,GAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAGvC,MAAM,iB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AAC,aAAa,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QACxD,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
2
+ import { Observable } from 'rxjs';
3
+ import { EntityManager } from '@mikro-orm/core';
4
+ export declare class CrudEntityInterceptor implements NestInterceptor {
5
+ private readonly em;
6
+ constructor(em: EntityManager);
7
+ intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>>;
8
+ }
9
+ export declare function InjectCrudEntity(): (target: Function) => void;
10
+ export declare const FetchedEntity: (...dataOrPipes: unknown[]) => ParameterDecorator;
@@ -0,0 +1,2 @@
1
+ export declare const READONLY_METADATA_KEY = "custom:readonly";
2
+ export declare function ReadOnly(): PropertyDecorator;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.READONLY_METADATA_KEY = void 0;
4
+ exports.ReadOnly = ReadOnly;
5
+ exports.READONLY_METADATA_KEY = 'custom:readonly';
6
+ function ReadOnly() {
7
+ return (target, propertyKey) => {
8
+ Reflect.defineMetadata(exports.READONLY_METADATA_KEY, true, target, propertyKey);
9
+ };
10
+ }
11
+ //# sourceMappingURL=readonly.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readonly.decorator.js","sourceRoot":"","sources":["../../../src/common/decorators/readonly.decorator.ts"],"names":[],"mappings":";;;AAEA,4BAIC;AANY,QAAA,qBAAqB,GAAG,iBAAiB,CAAC;AAEvD,SAAgB,QAAQ;IACtB,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,EAAE;QACtD,OAAO,CAAC,cAAc,CAAC,6BAAqB,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3E,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare class PaginationDto<T> {
2
+ page: number;
3
+ limit: number;
4
+ totalPages: number;
5
+ total: number;
6
+ data: T[];
7
+ }
@@ -0,0 +1,42 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PaginationDto = void 0;
13
+ const swagger_1 = require("@nestjs/swagger");
14
+ const class_transformer_1 = require("class-transformer");
15
+ class PaginationDto {
16
+ }
17
+ exports.PaginationDto = PaginationDto;
18
+ __decorate([
19
+ (0, class_transformer_1.Expose)(),
20
+ (0, swagger_1.ApiProperty)({ description: 'Page number', example: 1 }),
21
+ __metadata("design:type", Number)
22
+ ], PaginationDto.prototype, "page", void 0);
23
+ __decorate([
24
+ (0, class_transformer_1.Expose)(),
25
+ (0, swagger_1.ApiProperty)({ description: 'Limit number', example: 50 }),
26
+ __metadata("design:type", Number)
27
+ ], PaginationDto.prototype, "limit", void 0);
28
+ __decorate([
29
+ (0, class_transformer_1.Expose)(),
30
+ (0, swagger_1.ApiProperty)({ description: 'Total pages', example: 10 }),
31
+ __metadata("design:type", Number)
32
+ ], PaginationDto.prototype, "totalPages", void 0);
33
+ __decorate([
34
+ (0, class_transformer_1.Expose)(),
35
+ (0, swagger_1.ApiProperty)({ description: 'Total count', example: 100 }),
36
+ __metadata("design:type", Number)
37
+ ], PaginationDto.prototype, "total", void 0);
38
+ __decorate([
39
+ (0, class_transformer_1.Expose)(),
40
+ __metadata("design:type", Array)
41
+ ], PaginationDto.prototype, "data", void 0);
42
+ //# sourceMappingURL=pagination.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.dto.js","sourceRoot":"","sources":["../../../src/common/dto/pagination.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA8C;AAC9C,yDAA2C;AAE3C,MAAa,aAAa;CAmBzB;AAnBD,sCAmBC;AAhBG;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,qBAAW,EAAC,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;2CAC3C;AAIb;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,qBAAW,EAAC,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;4CAC5C;AAId;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,qBAAW,EAAC,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;iDACtC;AAInB;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,qBAAW,EAAC,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;;4CAC5C;AAGd;IADC,IAAA,0BAAM,GAAE;;2CACC"}
@@ -0,0 +1,28 @@
1
+ import { Type } from '@nestjs/common';
2
+ import { EntityData, FilterQuery } from '@mikro-orm/core';
3
+ export interface CrudOptions<T, C = EntityData<T>, U = EntityData<T>> {
4
+ tag?: string;
5
+ entity: Type<T>;
6
+ createDto?: Type<C>;
7
+ updateDto?: Type<U>;
8
+ defaultValues?: (request: Request, params: Record<string, string>) => EntityData<T> | Promise<EntityData<T>>;
9
+ operations?: {
10
+ create?: {} | false;
11
+ createMany?: {} | false;
12
+ update?: {} | false;
13
+ import?: {} | false;
14
+ query?: {
15
+ pagination?: boolean;
16
+ sort?: {
17
+ field: string;
18
+ order: 'ASC' | 'DESC';
19
+ }[];
20
+ } | false;
21
+ read?: {} | false;
22
+ delete?: {} | false;
23
+ replace?: {} | false;
24
+ export?: {} | false;
25
+ };
26
+ persist?: (request: Request, params: Record<string, string>) => EntityData<T> | Promise<EntityData<T>>;
27
+ filter?: (request: Request, params: Record<string, string>) => FilterQuery<T> | Promise<FilterQuery<T>>;
28
+ }
@@ -0,0 +1,5 @@
1
+ import { ClassConstructor } from "class-transformer";
2
+ export declare class ApiPropertyUtil {
3
+ static processApiParams(target: any): void;
4
+ static createApiEntity<X, T extends ClassConstructor<X>>(entity: T, visited?: Set<any>): void;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { AnyEntity } from '@mikro-orm/core';
2
+ import { CrudOptions } from '../interfaces/crud-options.interface';
3
+ export declare class DtoFactory {
4
+ static createDtos<T extends AnyEntity, C, U>(options: CrudOptions<T, C, U>): void;
5
+ }
@@ -0,0 +1,8 @@
1
+ export declare class EntityNameUtil {
2
+ static routeToName(route: string): string;
3
+ static classToName(entityClass: any): string;
4
+ static classToSlug(entityClass: any): string;
5
+ static getName(route?: string, entityClass?: any): string;
6
+ static pluralize(name: string): string;
7
+ static capitalize(name: string): string;
8
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntityNameUtil = void 0;
4
+ class EntityNameUtil {
5
+ static routeToName(route) {
6
+ return route.replace(/-/g, ' ').replace(/s$/, '').trim();
7
+ }
8
+ static classToName(entityClass) {
9
+ if (!entityClass || !entityClass.name) {
10
+ return 'item';
11
+ }
12
+ const name = entityClass.name
13
+ .replace(/([A-Z])/g, ' $1')
14
+ .toLowerCase()
15
+ .trim();
16
+ return name.replace(/\s+entity$/, '').trim();
17
+ }
18
+ static classToSlug(entityClass) {
19
+ if (!entityClass)
20
+ throw new Error('Entity class is required');
21
+ if (typeof entityClass !== 'string') {
22
+ entityClass = entityClass.name;
23
+ }
24
+ return entityClass
25
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
26
+ .toLowerCase();
27
+ }
28
+ static getName(route, entityClass) {
29
+ if (route) {
30
+ return this.routeToName(route);
31
+ }
32
+ if (entityClass) {
33
+ return this.classToName(entityClass);
34
+ }
35
+ return 'item';
36
+ }
37
+ static pluralize(name) {
38
+ if (name.endsWith('y')) {
39
+ return name.slice(0, -1) + 'ies';
40
+ }
41
+ if (name.endsWith('s') || name.endsWith('x') || name.endsWith('z') || name.endsWith('ch') || name.endsWith('sh')) {
42
+ return name + 'es';
43
+ }
44
+ return name + 's';
45
+ }
46
+ static capitalize(name) {
47
+ return name.split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
48
+ }
49
+ }
50
+ exports.EntityNameUtil = EntityNameUtil;
51
+ //# sourceMappingURL=entity-name.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-name.util.js","sourceRoot":"","sources":["../../../src/common/utils/entity-name.util.ts"],"names":[],"mappings":";;;AAGA,MAAa,cAAc;IAIzB,MAAM,CAAC,WAAW,CAAC,KAAa;QAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3D,CAAC;IAKD,MAAM,CAAC,WAAW,CAAC,WAAgB;QACjC,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YACtC,OAAO,MAAM,CAAC;QAChB,CAAC;QAID,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI;aAC1B,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;aAC1B,WAAW,EAAE;aACb,IAAI,EAAE,CAAC;QAGV,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/C,CAAC;IAKD,MAAM,CAAC,WAAW,CAAC,WAAgB;QACjC,IAAG,CAAC,WAAW;YAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAA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CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7F,CAAC;CACF;AAzED,wCAyEC"}
@@ -0,0 +1,10 @@
1
+ export * from './common/decorators/crud.decorator';
2
+ export * from './common/decorators/embedded.decorator';
3
+ export * from './common/decorators/readonly.decorator';
4
+ export * from './common/decorators/inject-entity.decorator';
5
+ export * from './common/base.service';
6
+ export * from './common/dto/pagination.dto';
7
+ export * from './common/utils/entity-name.util';
8
+ export * from './common/base.event';
9
+ export * from './common/base-related.service';
10
+ export * from './common/constants';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxiko/nest-common",
3
- "version": "0.2.26",
3
+ "version": "0.2.27",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "typings": "./build/index.d.ts",