law-common 10.29.0 → 10.30.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.
- package/dist/src/api/enums/crud.enum.d.ts +7 -0
- package/dist/src/api/enums/crud.enum.js +11 -0
- package/dist/src/api/index.d.ts +4 -0
- package/dist/src/api/index.js +8 -0
- package/dist/src/api/interface/address-book.create.dto.interface.d.ts +21 -0
- package/dist/src/api/interface/address-book.create.dto.interface.js +2 -0
- package/dist/src/api/interface/address-book.update.dto.interface.d.ts +3 -0
- package/dist/src/api/interface/address-book.update.dto.interface.js +25 -0
- package/dist/src/api/interface/api.utils.interface.d.ts +4 -0
- package/dist/src/api/interface/api.utils.interface.js +2 -0
- package/dist/src/entities/index.d.ts +3 -0
- package/dist/src/entities/index.js +3 -0
- package/dist/src/entities/interface/address-book.entity.interface.d.ts +11 -0
- package/dist/src/entities/interface/address-book.entity.interface.js +2 -0
- package/dist/src/entities/interface/entity.utils.interface.d.ts +7 -3
- package/dist/src/entities/interface/entity.utils.interface.js +1 -0
- package/dist/src/entities/model/address_book.model.d.ts +31 -0
- package/dist/src/entities/model/address_book.model.js +43 -0
- package/dist/src/entities/model/base.entity.model.d.ts +1 -1
- package/dist/src/entities/model/country.entity.model.d.ts +11 -0
- package/dist/src/entities/model/country.entity.model.js +21 -0
- package/dist/src/entities/model/entity.model.interface.d.ts +28 -5
- package/dist/src/entities/model/entity.model.interface.js +126 -40
- package/dist/src/utils/array.util.d.ts +25 -0
- package/dist/src/utils/array.util.js +168 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/index.js +1 -0
- package/dist/src/utils/object.util.d.ts +10 -0
- package/dist/src/utils/object.util.js +134 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CRUDEnum = void 0;
|
|
4
|
+
var CRUDEnum;
|
|
5
|
+
(function (CRUDEnum) {
|
|
6
|
+
CRUDEnum["CREATE"] = "CREATE";
|
|
7
|
+
CRUDEnum["READ"] = "READ";
|
|
8
|
+
CRUDEnum["UPDATE"] = "UPDATE";
|
|
9
|
+
CRUDEnum["DELETE"] = "DELETE";
|
|
10
|
+
CRUDEnum["UNCHANGED"] = "UNCHANGED";
|
|
11
|
+
})(CRUDEnum || (exports.CRUDEnum = CRUDEnum = {}));
|
package/dist/src/api/index.d.ts
CHANGED
|
@@ -48,3 +48,7 @@ export * from "./interface/work.from.home.create.dto.interface";
|
|
|
48
48
|
export * from "./interface/work.from.home.update.interface";
|
|
49
49
|
export * from "./interface/cron-job-manual-trigger.dto.interface";
|
|
50
50
|
export * from "./interface/cron-job.entity.response";
|
|
51
|
+
export * from "./interface/address-book.create.dto.interface";
|
|
52
|
+
export * from "./enums/crud.enum";
|
|
53
|
+
export * from "./interface/api.utils.interface";
|
|
54
|
+
export * from "./interface/address-book.update.dto.interface";
|
package/dist/src/api/index.js
CHANGED
|
@@ -64,3 +64,11 @@ __exportStar(require("./interface/work.from.home.create.dto.interface"), exports
|
|
|
64
64
|
__exportStar(require("./interface/work.from.home.update.interface"), exports);
|
|
65
65
|
__exportStar(require("./interface/cron-job-manual-trigger.dto.interface"), exports);
|
|
66
66
|
__exportStar(require("./interface/cron-job.entity.response"), exports);
|
|
67
|
+
// export * from "./interface/to-do.entity.api";
|
|
68
|
+
// export * from "./interface/billing-reimbursement-expense.api";
|
|
69
|
+
// export * from "./interface/billing-reimbursement-expense-history.api";
|
|
70
|
+
// export * from "./interface/project-user-mapping.entity.api";
|
|
71
|
+
__exportStar(require("./interface/address-book.create.dto.interface"), exports);
|
|
72
|
+
__exportStar(require("./enums/crud.enum"), exports);
|
|
73
|
+
__exportStar(require("./interface/api.utils.interface"), exports);
|
|
74
|
+
__exportStar(require("./interface/address-book.update.dto.interface"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IAddressBookEntity, IEntityCreateDto } from "../../entities";
|
|
2
|
+
import { CRUDEnum } from "../enums/crud.enum";
|
|
3
|
+
export type IAddressBookCreateExclude = "contactDetails" | "address" | "organizationId";
|
|
4
|
+
export interface IAddressBookContactDetail {
|
|
5
|
+
id?: number;
|
|
6
|
+
name: string;
|
|
7
|
+
email?: string;
|
|
8
|
+
phone?: string;
|
|
9
|
+
operation: CRUDEnum;
|
|
10
|
+
}
|
|
11
|
+
export interface IAddressBookAddress {
|
|
12
|
+
addressLine1?: string;
|
|
13
|
+
addressLine2?: string;
|
|
14
|
+
city?: string;
|
|
15
|
+
state?: string;
|
|
16
|
+
zipCode?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface IAddressBookCreateDto extends Omit<IEntityCreateDto<IAddressBookEntity>, IAddressBookCreateExclude> {
|
|
19
|
+
contactDetails: IAddressBookContactDetail[];
|
|
20
|
+
address?: IAddressBookAddress;
|
|
21
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// export type IAddressBookUpdateDto = DeepPartialButRequired<
|
|
4
|
+
// Omit<IAddressBookCreateDto, 'contactDetails'>,
|
|
5
|
+
// never
|
|
6
|
+
// > & {
|
|
7
|
+
// contactDetails?: DeepPartialButRequired<IAddressBookContactDetail, 'id'>[]; // id required per item
|
|
8
|
+
// // address?: DeepPartial<IAddressBookAddress>;
|
|
9
|
+
// };
|
|
10
|
+
// const a: IAddressBookUpdateDto = {
|
|
11
|
+
// organizationName: "Test Name",
|
|
12
|
+
// contactDetails: [
|
|
13
|
+
// {
|
|
14
|
+
// id: 1,
|
|
15
|
+
// email: "test@example.com",
|
|
16
|
+
// phone: "123-456-7890"
|
|
17
|
+
// }
|
|
18
|
+
// ]
|
|
19
|
+
// };
|
|
20
|
+
// const b: IAddressBookUpdateDto = {
|
|
21
|
+
// organizationName: "Test Name",
|
|
22
|
+
// address: {
|
|
23
|
+
// city: "Sample City"
|
|
24
|
+
// }
|
|
25
|
+
// };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type DeepPartial<T> = T extends object ? {
|
|
2
|
+
[P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
3
|
+
} : T;
|
|
4
|
+
export type DeepPartialButRequired<T, K extends keyof T> = DeepPartial<T> & Required<Pick<T, K>>;
|
|
@@ -63,6 +63,7 @@ export * from "./interface/billing_timesheet.entity.interface";
|
|
|
63
63
|
export * from "./interface/intermediary_bank.entity.interface";
|
|
64
64
|
export * from "./interface/holiday-list.entity.interface";
|
|
65
65
|
export * from "./interface/holiday.entity.interface";
|
|
66
|
+
export * from "./interface/address-book.entity.interface";
|
|
66
67
|
export * from "./model/leave.entity.model";
|
|
67
68
|
export * from "./model/leave_count.entity.model";
|
|
68
69
|
export * from "./model/holiday.entity.model";
|
|
@@ -96,8 +97,10 @@ export * from "./model/timesheet.entity.model";
|
|
|
96
97
|
export * from "./model/user.entity.model";
|
|
97
98
|
export * from "./model/client-affiliate.entity.model";
|
|
98
99
|
export * from "./model/billing-timesheet.entity.model";
|
|
100
|
+
export * from "./model/country.entity.model";
|
|
99
101
|
export * from "./interface/entity-audit-columns.interface";
|
|
100
102
|
export * from "./enums/billing-transaction-action.enum";
|
|
101
103
|
export * from "./enums/billing-transaction-status.enum";
|
|
102
104
|
export * from "./interface/billing-transaction-history.entity";
|
|
103
105
|
export * from "./model/billing-transaction.model";
|
|
106
|
+
export * from "./interface/address-book.entity.interface";
|
|
@@ -79,6 +79,7 @@ __exportStar(require("./interface/billing_timesheet.entity.interface"), exports)
|
|
|
79
79
|
__exportStar(require("./interface/intermediary_bank.entity.interface"), exports);
|
|
80
80
|
__exportStar(require("./interface/holiday-list.entity.interface"), exports);
|
|
81
81
|
__exportStar(require("./interface/holiday.entity.interface"), exports);
|
|
82
|
+
__exportStar(require("./interface/address-book.entity.interface"), exports);
|
|
82
83
|
__exportStar(require("./model/leave.entity.model"), exports);
|
|
83
84
|
__exportStar(require("./model/leave_count.entity.model"), exports);
|
|
84
85
|
__exportStar(require("./model/holiday.entity.model"), exports);
|
|
@@ -112,8 +113,10 @@ __exportStar(require("./model/timesheet.entity.model"), exports);
|
|
|
112
113
|
__exportStar(require("./model/user.entity.model"), exports);
|
|
113
114
|
__exportStar(require("./model/client-affiliate.entity.model"), exports);
|
|
114
115
|
__exportStar(require("./model/billing-timesheet.entity.model"), exports);
|
|
116
|
+
__exportStar(require("./model/country.entity.model"), exports);
|
|
115
117
|
__exportStar(require("./interface/entity-audit-columns.interface"), exports);
|
|
116
118
|
__exportStar(require("./enums/billing-transaction-action.enum"), exports);
|
|
117
119
|
__exportStar(require("./enums/billing-transaction-status.enum"), exports);
|
|
118
120
|
__exportStar(require("./interface/billing-transaction-history.entity"), exports);
|
|
119
121
|
__exportStar(require("./model/billing-transaction.model"), exports);
|
|
122
|
+
__exportStar(require("./interface/address-book.entity.interface"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IEntityAuditColumn } from "./entity-audit-columns.interface";
|
|
2
|
+
export interface IAddressBookEntity extends IEntityAuditColumn {
|
|
3
|
+
id: number;
|
|
4
|
+
organizationName: string;
|
|
5
|
+
contactDetails: string;
|
|
6
|
+
address?: string;
|
|
7
|
+
country: string;
|
|
8
|
+
notes?: string;
|
|
9
|
+
organizationId: number;
|
|
10
|
+
introducedBy?: number;
|
|
11
|
+
}
|
|
@@ -3,6 +3,7 @@ import { ConvertToArray } from "../../misc";
|
|
|
3
3
|
import { Modify } from "../../misc/interface/modify.interface";
|
|
4
4
|
import { EntitySearchConstraintTypeEnum } from "../enums/entity_search_constraint_type.enum";
|
|
5
5
|
import { HistoryOperationEnum } from "../enums/history_operation.enum";
|
|
6
|
+
import { AddressBookEntityModel } from "../model/address_book.model";
|
|
6
7
|
import { BankEntityModel } from "../model/bank.entity.model";
|
|
7
8
|
import { BillingReimbursementExpneseEntityModel } from "../model/billing-reimbursement-expense.entity.model";
|
|
8
9
|
import { BillingTimesheetEntityModel } from "../model/billing-timesheet.entity.model";
|
|
@@ -11,6 +12,7 @@ import { BillingEntityModel } from "../model/billing.entity.model";
|
|
|
11
12
|
import { ClientAffiliateEntityModel } from "../model/client-affiliate.entity.model";
|
|
12
13
|
import { ClientEntityModel } from "../model/client.entity.model";
|
|
13
14
|
import { ConfigurationEntityModel } from "../model/configuration.model";
|
|
15
|
+
import { CountryEntityModel } from "../model/country.entity.model";
|
|
14
16
|
import { HolidayEntityModel } from "../model/holiday.entity.model";
|
|
15
17
|
import { LeaveEntityModel } from "../model/leave.entity.model";
|
|
16
18
|
import { LeaveCountVirtualEntityModel } from "../model/leave_count.entity.model";
|
|
@@ -21,6 +23,7 @@ import { ReimbursementEntityModel } from "../model/reimbursement.entity.model";
|
|
|
21
23
|
import { TaskEntityModel } from "../model/task.entity.model";
|
|
22
24
|
import { TimesheetEntityModel } from "../model/timesheet.entity.model";
|
|
23
25
|
import { UserEntityModel } from "../model/user.entity.model";
|
|
26
|
+
import { IAddressBookEntity } from "./address-book.entity.interface";
|
|
24
27
|
import { IBankEntity } from "./bank.entity.interface";
|
|
25
28
|
import { IBankHistoryEntity } from "./bank_history.entity.interface";
|
|
26
29
|
import { IBillingReimbursementExpenseEntity } from "./billing-reimbursement-expense.entity.interface";
|
|
@@ -139,7 +142,8 @@ export declare enum EntityEnum {
|
|
|
139
142
|
HOLIDAY = "holiday",
|
|
140
143
|
HOLIDAY_LIST = "holiday_list",
|
|
141
144
|
CRON_JOBS = "cron_jobs",
|
|
142
|
-
TO_DO_LIST = "to_do_list"
|
|
145
|
+
TO_DO_LIST = "to_do_list",
|
|
146
|
+
ADDRESS_BOOK = "address_book"
|
|
143
147
|
}
|
|
144
148
|
export type EntityRelations = {
|
|
145
149
|
[K in EntityEnum | VirtualEntityEnum]: K;
|
|
@@ -158,7 +162,7 @@ export type IBaseEntityApiResponse<T> = {
|
|
|
158
162
|
[K in EntityEnum | VirtualEntityEnum]?: IBaseEntityApiResponse<EnumEntityType<K>>;
|
|
159
163
|
};
|
|
160
164
|
};
|
|
161
|
-
export type EnumEntityType<T extends EntityEnum | VirtualEntityEnum> = (T extends EntityEnum.BILLING ? IBillingEntity : T extends EntityEnum.BILLING_TIMESHEET ? IBillingTimesheetEntity : T extends EntityEnum.BILLING_REIMBURSEMENT_EXPENSE ? IBillingReimbursementExpenseEntity : T extends EntityEnum.TIMESHEET ? ITimesheetEntity : T extends EntityEnum.USER ? IUserEntity : T extends EntityEnum.PROJECT ? IProjectEntity : T extends EntityEnum.CLIENT ? IClientEntity : T extends EntityEnum.LEAVE ? ILeaveEntity : T extends EntityEnum.BANK ? IBankEntity : T extends EntityEnum.BILLING_PAYMENT ? IBillingPaymentEntity : T extends EntityEnum.BILLING_TRANSACTION ? IBillingTransactionEntity : T extends EntityEnum.BILLING_TRANSACTION_HISTORY ? IBillingTransactionHistoryEntity : T extends EntityEnum.CLIENT_AFFILIATE ? IClientAffiliateEntity : T extends EntityEnum.CONFIGURATION ? IConfigurationEntity : T extends EntityEnum.HOLIDAY ? IHolidayEntity : T extends EntityEnum.HOLIDAY_LIST ? IHolidayListEntity : T extends EntityEnum.COUNTRY ? ICountryEntity : T extends EntityEnum.EXPENSE_TYPE ? IExpenseTypeEntity : T extends EntityEnum.INDUSTRY ? IIndustryEntity : T extends EntityEnum.INTERMEDIARY_BANK ? IIntermediaryBankEntity : T extends EntityEnum.OFFICE_LOCATION ? IOfficeLocationEntity : T extends EntityEnum.PERMISSION ? IPermissionEntity : T extends EntityEnum.ROLE ? IRoleEntity : T extends EntityEnum.TASK ? ITaskEntity : T extends EntityEnum.DESIGNATION ? IDesignationEntity : T extends EntityEnum.RATE ? IRateEntity : T extends EntityEnum.REIMBURSEMENT ? IReimbursementEntity : T extends EntityEnum.REIMBURSEMENT_EXPENSE ? IReimbursementExpenseEntity : T extends EntityEnum.WORK_FROM_HOME ? IWorkFromHomeEntity : T extends EntityEnum.ORGANIZATION ? IOrganizationEntity : T extends EntityEnum.PROJECT_USER_MAPPING ? IProjectUserMappingEntity : T extends EntityEnum.CLIENT_USER_MAPPING ? IClientUserMappingEntity : T extends EntityEnum.TO_DO_LIST ? IToDoListEntity : T extends EntityEnum.CRON_JOBS ? ICronJobsEntity : T extends EntityEnum.ROLE_PERMISSION_MAPPING ? IRolePermissionMappingEntity : T extends EntityEnum.BANK_HISTORY ? IBankHistoryEntity : T extends VirtualEntityEnum.LEAVE_COUNT ? ILeaveCountVirtualEntity : T extends EntityEnum.LEAVE_HISTORY ? ILeaveHistoryEntity : T extends EntityEnum.WORK_FROM_HOME_HISTORY ? IWorkFromHomeHistoryEntity : T extends EntityEnum.TIMESHEET_HISTORY ? ITimesheetHistoryEntity : never) & {
|
|
165
|
+
export type EnumEntityType<T extends EntityEnum | VirtualEntityEnum> = (T extends EntityEnum.BILLING ? IBillingEntity : T extends EntityEnum.BILLING_TIMESHEET ? IBillingTimesheetEntity : T extends EntityEnum.BILLING_REIMBURSEMENT_EXPENSE ? IBillingReimbursementExpenseEntity : T extends EntityEnum.TIMESHEET ? ITimesheetEntity : T extends EntityEnum.USER ? IUserEntity : T extends EntityEnum.PROJECT ? IProjectEntity : T extends EntityEnum.CLIENT ? IClientEntity : T extends EntityEnum.LEAVE ? ILeaveEntity : T extends EntityEnum.BANK ? IBankEntity : T extends EntityEnum.BILLING_PAYMENT ? IBillingPaymentEntity : T extends EntityEnum.BILLING_TRANSACTION ? IBillingTransactionEntity : T extends EntityEnum.BILLING_TRANSACTION_HISTORY ? IBillingTransactionHistoryEntity : T extends EntityEnum.CLIENT_AFFILIATE ? IClientAffiliateEntity : T extends EntityEnum.CONFIGURATION ? IConfigurationEntity : T extends EntityEnum.HOLIDAY ? IHolidayEntity : T extends EntityEnum.HOLIDAY_LIST ? IHolidayListEntity : T extends EntityEnum.COUNTRY ? ICountryEntity : T extends EntityEnum.EXPENSE_TYPE ? IExpenseTypeEntity : T extends EntityEnum.INDUSTRY ? IIndustryEntity : T extends EntityEnum.INTERMEDIARY_BANK ? IIntermediaryBankEntity : T extends EntityEnum.OFFICE_LOCATION ? IOfficeLocationEntity : T extends EntityEnum.PERMISSION ? IPermissionEntity : T extends EntityEnum.ROLE ? IRoleEntity : T extends EntityEnum.TASK ? ITaskEntity : T extends EntityEnum.DESIGNATION ? IDesignationEntity : T extends EntityEnum.RATE ? IRateEntity : T extends EntityEnum.REIMBURSEMENT ? IReimbursementEntity : T extends EntityEnum.REIMBURSEMENT_EXPENSE ? IReimbursementExpenseEntity : T extends EntityEnum.WORK_FROM_HOME ? IWorkFromHomeEntity : T extends EntityEnum.ORGANIZATION ? IOrganizationEntity : T extends EntityEnum.PROJECT_USER_MAPPING ? IProjectUserMappingEntity : T extends EntityEnum.CLIENT_USER_MAPPING ? IClientUserMappingEntity : T extends EntityEnum.TO_DO_LIST ? IToDoListEntity : T extends EntityEnum.CRON_JOBS ? ICronJobsEntity : T extends EntityEnum.ROLE_PERMISSION_MAPPING ? IRolePermissionMappingEntity : T extends EntityEnum.BANK_HISTORY ? IBankHistoryEntity : T extends VirtualEntityEnum.LEAVE_COUNT ? ILeaveCountVirtualEntity : T extends EntityEnum.LEAVE_HISTORY ? ILeaveHistoryEntity : T extends EntityEnum.WORK_FROM_HOME_HISTORY ? IWorkFromHomeHistoryEntity : T extends EntityEnum.TIMESHEET_HISTORY ? ITimesheetHistoryEntity : T extends EntityEnum.ADDRESS_BOOK ? IAddressBookEntity : never) & {
|
|
162
166
|
id: number;
|
|
163
167
|
};
|
|
164
168
|
export type EntityRelationConfig<T extends EntityEnum | VirtualEntityEnum> = {
|
|
@@ -281,7 +285,7 @@ export declare enum VirtualEntityEnum {
|
|
|
281
285
|
}
|
|
282
286
|
export type IHistoryConstraintSearchResponse<T> = IBaseResponse<IHistoryEntitySearchByConstraintResponse<T>[]>;
|
|
283
287
|
export type IHistoryConstraintSearchServiceResponse<T> = IHistoryEntitySearchByConstraintResponse<T>[];
|
|
284
|
-
export type EnumToModel<T extends EntityEnum | VirtualEntityEnum> = T extends EntityEnum.BILLING ? BillingEntityModel : T extends EntityEnum.CLIENT ? ClientEntityModel : T extends EntityEnum.PROJECT ? ProjectEntityModel : T extends EntityEnum.PROJECT_USER_MAPPING ? ProjectUserMappingEntityModel : T extends EntityEnum.REIMBURSEMENT ? ReimbursementEntityModel : T extends EntityEnum.REIMBURSEMENT_EXPENSE ? ReimbursementExpenseEntityModel : T extends EntityEnum.BILLING_REIMBURSEMENT_EXPENSE ? BillingReimbursementExpneseEntityModel : T extends EntityEnum.LEAVE ? LeaveEntityModel : T extends EntityEnum.HOLIDAY ? HolidayEntityModel : T extends VirtualEntityEnum.LEAVE_COUNT ? LeaveCountVirtualEntityModel : T extends EntityEnum.CLIENT_AFFILIATE ? ClientAffiliateEntityModel : T extends EntityEnum.BANK ? BankEntityModel : T extends EntityEnum.CONFIGURATION ? ConfigurationEntityModel : T extends EntityEnum.TASK ? TaskEntityModel : T extends EntityEnum.BILLING_TIMESHEET ? BillingTimesheetEntityModel : T extends EntityEnum.TIMESHEET ? TimesheetEntityModel : T extends EntityEnum.BILLING_TRANSACTION ? BillingTransactionEntityModel : UserEntityModel;
|
|
288
|
+
export type EnumToModel<T extends EntityEnum | VirtualEntityEnum> = T extends EntityEnum.BILLING ? BillingEntityModel : T extends EntityEnum.CLIENT ? ClientEntityModel : T extends EntityEnum.PROJECT ? ProjectEntityModel : T extends EntityEnum.PROJECT_USER_MAPPING ? ProjectUserMappingEntityModel : T extends EntityEnum.REIMBURSEMENT ? ReimbursementEntityModel : T extends EntityEnum.REIMBURSEMENT_EXPENSE ? ReimbursementExpenseEntityModel : T extends EntityEnum.BILLING_REIMBURSEMENT_EXPENSE ? BillingReimbursementExpneseEntityModel : T extends EntityEnum.LEAVE ? LeaveEntityModel : T extends EntityEnum.HOLIDAY ? HolidayEntityModel : T extends VirtualEntityEnum.LEAVE_COUNT ? LeaveCountVirtualEntityModel : T extends EntityEnum.CLIENT_AFFILIATE ? ClientAffiliateEntityModel : T extends EntityEnum.BANK ? BankEntityModel : T extends EntityEnum.CONFIGURATION ? ConfigurationEntityModel : T extends EntityEnum.TASK ? TaskEntityModel : T extends EntityEnum.BILLING_TIMESHEET ? BillingTimesheetEntityModel : T extends EntityEnum.TIMESHEET ? TimesheetEntityModel : T extends EntityEnum.COUNTRY ? CountryEntityModel : T extends EntityEnum.BILLING_TRANSACTION ? BillingTransactionEntityModel : T extends EntityEnum.ADDRESS_BOOK ? AddressBookEntityModel : UserEntityModel;
|
|
285
289
|
export type EntityMap = {
|
|
286
290
|
[key in EntityEnum | VirtualEntityEnum]: EnumToModel<key>[];
|
|
287
291
|
};
|
|
@@ -77,6 +77,7 @@ var EntityEnum;
|
|
|
77
77
|
EntityEnum["HOLIDAY_LIST"] = "holiday_list";
|
|
78
78
|
EntityEnum["CRON_JOBS"] = "cron_jobs";
|
|
79
79
|
EntityEnum["TO_DO_LIST"] = "to_do_list";
|
|
80
|
+
EntityEnum["ADDRESS_BOOK"] = "address_book";
|
|
80
81
|
})(EntityEnum || (exports.EntityEnum = EntityEnum = {}));
|
|
81
82
|
var VirtualEntityEnum;
|
|
82
83
|
(function (VirtualEntityEnum) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RelationType } from "../enums/relation-type.enum";
|
|
2
|
+
import { IAddressBookEntity } from "../interface/address-book.entity.interface";
|
|
3
|
+
import { EntityEnum } from "../interface/entity.utils.interface";
|
|
4
|
+
import { BaseEntityModel } from "./base.entity.model";
|
|
5
|
+
import { UserEntityModel } from "./user.entity.model";
|
|
6
|
+
export declare class AddressBookEntityModel extends BaseEntityModel<EntityEnum.ADDRESS_BOOK> implements IAddressBookEntity {
|
|
7
|
+
id: number;
|
|
8
|
+
organizationName: string;
|
|
9
|
+
contactDetails: string;
|
|
10
|
+
address?: string | undefined;
|
|
11
|
+
country: string;
|
|
12
|
+
notes?: string | undefined;
|
|
13
|
+
organizationId: number;
|
|
14
|
+
introducedBy?: number | undefined;
|
|
15
|
+
createdOn: number;
|
|
16
|
+
updatedOn: number;
|
|
17
|
+
createdBy: number;
|
|
18
|
+
updatedBy: number;
|
|
19
|
+
introducedByUser?: UserEntityModel | undefined;
|
|
20
|
+
static fromEntity(entity: IAddressBookEntity): AddressBookEntityModel;
|
|
21
|
+
static relationConfigs: {
|
|
22
|
+
name: EntityEnum;
|
|
23
|
+
relation: RelationType;
|
|
24
|
+
key: string;
|
|
25
|
+
mapKeyConfig: {
|
|
26
|
+
relationKey: string;
|
|
27
|
+
key: string;
|
|
28
|
+
};
|
|
29
|
+
}[];
|
|
30
|
+
getRelationConfigs(): any[];
|
|
31
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AddressBookEntityModel = void 0;
|
|
4
|
+
const relation_type_enum_1 = require("../enums/relation-type.enum");
|
|
5
|
+
const entity_utils_interface_1 = require("../interface/entity.utils.interface");
|
|
6
|
+
const base_entity_model_1 = require("./base.entity.model");
|
|
7
|
+
class AddressBookEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.id = 0;
|
|
11
|
+
this.organizationName = "";
|
|
12
|
+
this.contactDetails = "";
|
|
13
|
+
this.address = "";
|
|
14
|
+
this.country = "";
|
|
15
|
+
this.notes = "";
|
|
16
|
+
this.organizationId = 0;
|
|
17
|
+
this.introducedBy = 0;
|
|
18
|
+
this.createdOn = 0;
|
|
19
|
+
this.updatedOn = 0;
|
|
20
|
+
this.createdBy = 0;
|
|
21
|
+
this.updatedBy = 0;
|
|
22
|
+
}
|
|
23
|
+
static fromEntity(entity) {
|
|
24
|
+
const result = new AddressBookEntityModel(entity_utils_interface_1.EntityEnum.ADDRESS_BOOK);
|
|
25
|
+
Object.assign(result, entity);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
getRelationConfigs() {
|
|
29
|
+
return this.constructor.prototype.constructor.relationConfigs || [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.AddressBookEntityModel = AddressBookEntityModel;
|
|
33
|
+
AddressBookEntityModel.relationConfigs = [
|
|
34
|
+
{
|
|
35
|
+
name: entity_utils_interface_1.EntityEnum.USER,
|
|
36
|
+
relation: relation_type_enum_1.RelationType.ONE,
|
|
37
|
+
key: "introducedByUser",
|
|
38
|
+
mapKeyConfig: {
|
|
39
|
+
relationKey: "id",
|
|
40
|
+
key: "introducedBy",
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
];
|
|
@@ -4,7 +4,7 @@ export declare enum RelationType {
|
|
|
4
4
|
MANY = "many"
|
|
5
5
|
}
|
|
6
6
|
export declare abstract class BaseEntityModel<T extends EntityEnum | VirtualEntityEnum> {
|
|
7
|
-
|
|
7
|
+
readonly entityName: T;
|
|
8
8
|
constructor(entityName: T);
|
|
9
9
|
abstract getRelationConfigs(): any[];
|
|
10
10
|
populateRelationsByIndex(entityIndexMap: EntityIndexMap): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ICountryEntity } from "../interface/country.entity.interface";
|
|
2
|
+
export declare class CountryEntityModel implements ICountryEntity {
|
|
3
|
+
id: number;
|
|
4
|
+
name: string;
|
|
5
|
+
createdBy: number;
|
|
6
|
+
updatedBy: number;
|
|
7
|
+
createdOn: number;
|
|
8
|
+
updatedOn: number;
|
|
9
|
+
constructor(data?: ICountryEntity);
|
|
10
|
+
static fromApiEntity(apiEntity: ICountryEntity): CountryEntityModel;
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { ICountryApiEntity } from "../../api";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.CountryEntityModel = void 0;
|
|
5
|
+
class CountryEntityModel {
|
|
6
|
+
constructor(data) {
|
|
7
|
+
this.id = 0;
|
|
8
|
+
this.name = "";
|
|
9
|
+
this.createdBy = 0;
|
|
10
|
+
this.updatedBy = 0;
|
|
11
|
+
this.createdOn = 0;
|
|
12
|
+
this.updatedOn = 0;
|
|
13
|
+
Object.assign(this, data);
|
|
14
|
+
}
|
|
15
|
+
static fromApiEntity(apiEntity) {
|
|
16
|
+
const entity = new CountryEntityModel(apiEntity);
|
|
17
|
+
Object.assign(entity, apiEntity);
|
|
18
|
+
return entity;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.CountryEntityModel = CountryEntityModel;
|
|
@@ -1,19 +1,42 @@
|
|
|
1
1
|
import { EntityEnum, EntityIndexMap, EntityMap, EnumEntityType, EnumToModel, IApiEntity, IBaseEntityApiResponse, VirtualEntityEnum } from "../interface/entity.utils.interface";
|
|
2
|
+
import { BaseEntityModel } from "./base.entity.model";
|
|
2
3
|
export declare function mapToIndex(entityMap: EntityMap): EntityIndexMap;
|
|
3
4
|
export declare function getEntityIndexMap<T extends EntityEnum>(data: IBaseEntityApiResponse<EnumEntityType<T>>, baseEntity: T, reusedConfig?: {
|
|
4
5
|
existingEntityIndexMap: EntityIndexMap;
|
|
5
6
|
enumEntities: EntityEnum[];
|
|
6
7
|
}): EntityIndexMap;
|
|
7
8
|
export declare function populateRelationsFor(entityIndexMap: EntityIndexMap, enumEntities: EntityEnum[]): void;
|
|
8
|
-
export declare function parseEntities<T extends EnumEntityType<EntityEnum>>(json: IBaseEntityApiResponse<T>, baseEntity: EntityEnum, entityMap: EntityMap): EntityMap;
|
|
9
9
|
export declare const entityEnumToEntityModel: {
|
|
10
|
-
[E in EntityEnum | VirtualEntityEnum]?: (json:
|
|
11
|
-
createdOn: number;
|
|
12
|
-
updatedOn: number;
|
|
13
|
-
}) => EnumToModel<E>;
|
|
10
|
+
[E in EntityEnum | VirtualEntityEnum]?: (json: EnumEntityType<E>) => EnumToModel<E>;
|
|
14
11
|
};
|
|
12
|
+
export declare function entityMapToModels(entityMap: EntityMap): void;
|
|
13
|
+
export declare function parseEntities<T extends EnumEntityType<EntityEnum | VirtualEntityEnum>>(json: IBaseEntityApiResponse<T>, baseEntity: EntityEnum | VirtualEntityEnum, entityMap: EntityMap): EntityMap;
|
|
14
|
+
export declare function entityMapToEntityIndexMap(entityMap: EntityMap, entityRelationsFor: EntityEnum[]): EntityIndexMap;
|
|
15
15
|
export declare function parseEntitiesWithoutModels<T extends EnumEntityType<EntityEnum | VirtualEntityEnum>>(json: IBaseEntityApiResponse<T>, baseEntity: EntityEnum | VirtualEntityEnum, entityMap?: {
|
|
16
16
|
[E in EntityEnum | VirtualEntityEnum]?: IApiEntity<EnumEntityType<E>>[];
|
|
17
17
|
}): {
|
|
18
18
|
[E in EntityEnum | VirtualEntityEnum]?: IApiEntity<EnumEntityType<E>>[];
|
|
19
19
|
};
|
|
20
|
+
export declare function removeEntityById(entityIndexMap: EntityIndexMap, entity: EntityEnum, id: number): void;
|
|
21
|
+
export declare class EntityModelRelationHelper {
|
|
22
|
+
entityMap: EntityMap;
|
|
23
|
+
entityModelMap: EntityMap;
|
|
24
|
+
entityModelIndexMap: EntityIndexMap;
|
|
25
|
+
constructor(entityMap: EntityMap);
|
|
26
|
+
private init;
|
|
27
|
+
private toEntityModelMap;
|
|
28
|
+
fromEntityToEntityModel<T extends EntityEnum | VirtualEntityEnum>(entity: EnumEntityType<T>, entityEnum: T): BaseEntityModel<T>;
|
|
29
|
+
private toEntityModelIndexMap;
|
|
30
|
+
populateRelationsByEntityEnums(entityEnums: EntityEnum[]): EntityModelRelationHelper;
|
|
31
|
+
populateRelationsByEntityEnum(entityEnum: EntityEnum): void;
|
|
32
|
+
populateRelationsByEntityModel(entityModel: BaseEntityModel<EntityEnum | VirtualEntityEnum>): void;
|
|
33
|
+
addEntityModel<T extends EntityEnum | VirtualEntityEnum>(entityModel: BaseEntityModel<T>, config?: {
|
|
34
|
+
populateRelations?: boolean;
|
|
35
|
+
}): void;
|
|
36
|
+
addEntity<T extends EntityEnum | VirtualEntityEnum>(entity: EnumEntityType<T>, entityEnum: T, config?: {
|
|
37
|
+
populateRelations?: boolean;
|
|
38
|
+
}): void;
|
|
39
|
+
updateEntityModel<T extends EntityEnum | VirtualEntityEnum>(entityModel: BaseEntityModel<T>, config?: {
|
|
40
|
+
populateRelations?: boolean;
|
|
41
|
+
}): void;
|
|
42
|
+
}
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.entityEnumToEntityModel = void 0;
|
|
3
|
+
exports.EntityModelRelationHelper = exports.entityEnumToEntityModel = void 0;
|
|
4
4
|
exports.mapToIndex = mapToIndex;
|
|
5
5
|
exports.getEntityIndexMap = getEntityIndexMap;
|
|
6
6
|
exports.populateRelationsFor = populateRelationsFor;
|
|
7
|
+
exports.entityMapToModels = entityMapToModels;
|
|
7
8
|
exports.parseEntities = parseEntities;
|
|
9
|
+
exports.entityMapToEntityIndexMap = entityMapToEntityIndexMap;
|
|
8
10
|
exports.parseEntitiesWithoutModels = parseEntitiesWithoutModels;
|
|
11
|
+
exports.removeEntityById = removeEntityById;
|
|
9
12
|
const entity_utils_interface_1 = require("../interface/entity.utils.interface");
|
|
10
13
|
const bank_entity_model_1 = require("./bank.entity.model");
|
|
11
14
|
const base_entity_model_1 = require("./base.entity.model");
|
|
12
15
|
const billing_reimbursement_expense_entity_model_1 = require("./billing-reimbursement-expense.entity.model");
|
|
13
16
|
const billing_timesheet_entity_model_1 = require("./billing-timesheet.entity.model");
|
|
14
|
-
const billing_transaction_model_1 = require("./billing-transaction.model");
|
|
15
17
|
const billing_entity_model_1 = require("./billing.entity.model");
|
|
16
18
|
const client_affiliate_entity_model_1 = require("./client-affiliate.entity.model");
|
|
17
19
|
const client_entity_model_1 = require("./client.entity.model");
|
|
18
|
-
const configuration_model_1 = require("./configuration.model");
|
|
19
20
|
const holiday_entity_model_1 = require("./holiday.entity.model");
|
|
20
21
|
const leave_entity_model_1 = require("./leave.entity.model");
|
|
21
22
|
const leave_count_entity_model_1 = require("./leave_count.entity.model");
|
|
23
|
+
const configuration_model_1 = require("./configuration.model");
|
|
22
24
|
const project_user_mapping_entity_model_1 = require("./project-user-mapping.entity.model");
|
|
23
25
|
const project_entity_model_1 = require("./project.entity.model");
|
|
24
26
|
const reimbursement_expense_entity_model_1 = require("./reimbursement-expense.entity.model");
|
|
@@ -26,6 +28,8 @@ const reimbursement_entity_model_1 = require("./reimbursement.entity.model");
|
|
|
26
28
|
const task_entity_model_1 = require("./task.entity.model");
|
|
27
29
|
const timesheet_entity_model_1 = require("./timesheet.entity.model");
|
|
28
30
|
const user_entity_model_1 = require("./user.entity.model");
|
|
31
|
+
const country_entity_model_1 = require("./country.entity.model");
|
|
32
|
+
const address_book_model_1 = require("./address_book.model");
|
|
29
33
|
function mapToIndex(entityMap) {
|
|
30
34
|
return Object.keys(entityMap).reduce((acc, key) => {
|
|
31
35
|
// @ts-ignore
|
|
@@ -53,41 +57,6 @@ function populateRelationsFor(entityIndexMap, enumEntities) {
|
|
|
53
57
|
base_entity_model_1.BaseEntityModel.populateRelationsForEntities(entityIndexMap, entity);
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
|
-
function parseEntities(json, baseEntity, entityMap) {
|
|
57
|
-
var _a;
|
|
58
|
-
const entityFromJsonMappings = {
|
|
59
|
-
[entity_utils_interface_1.EntityEnum.PROJECT]: project_entity_model_1.ProjectEntityModel.fromEntity,
|
|
60
|
-
[entity_utils_interface_1.EntityEnum.CLIENT]: client_entity_model_1.ClientEntityModel.fromEntity,
|
|
61
|
-
[entity_utils_interface_1.EntityEnum.BILLING]: billing_entity_model_1.BillingEntityModel.fromEntity,
|
|
62
|
-
[entity_utils_interface_1.EntityEnum.USER]: user_entity_model_1.UserEntityModel.fromEntity,
|
|
63
|
-
[entity_utils_interface_1.EntityEnum.PROJECT_USER_MAPPING]: project_user_mapping_entity_model_1.ProjectUserMappingEntityModel.fromEntity,
|
|
64
|
-
[entity_utils_interface_1.EntityEnum.REIMBURSEMENT]: reimbursement_entity_model_1.ReimbursementEntityModel.fromEntity,
|
|
65
|
-
[entity_utils_interface_1.EntityEnum.REIMBURSEMENT_EXPENSE]: reimbursement_expense_entity_model_1.ReimbursementExpenseEntityModel.fromEntity,
|
|
66
|
-
[entity_utils_interface_1.EntityEnum.BILLING_REIMBURSEMENT_EXPENSE]: billing_reimbursement_expense_entity_model_1.BillingReimbursementExpneseEntityModel.fromEntity,
|
|
67
|
-
[entity_utils_interface_1.EntityEnum.CLIENT_AFFILIATE]: client_affiliate_entity_model_1.ClientAffiliateEntityModel.fromEntity,
|
|
68
|
-
[entity_utils_interface_1.EntityEnum.BANK]: bank_entity_model_1.BankEntityModel.fromEntity,
|
|
69
|
-
[entity_utils_interface_1.EntityEnum.CONFIGURATION]: configuration_model_1.ConfigurationEntityModel.fromEntity,
|
|
70
|
-
[entity_utils_interface_1.EntityEnum.TASK]: task_entity_model_1.TaskEntityModel.fromEntity,
|
|
71
|
-
[entity_utils_interface_1.EntityEnum.BILLING_TIMESHEET]: billing_timesheet_entity_model_1.BillingTimesheetEntityModel.fromEntity,
|
|
72
|
-
[entity_utils_interface_1.EntityEnum.TIMESHEET]: timesheet_entity_model_1.TimesheetEntityModel.fromEntity,
|
|
73
|
-
[entity_utils_interface_1.EntityEnum.BILLING_TRANSACTION]: billing_transaction_model_1.BillingTransactionEntityModel.fromEntity,
|
|
74
|
-
};
|
|
75
|
-
if (!(baseEntity in entityFromJsonMappings)) {
|
|
76
|
-
throw new Error(`Unknown entity: ${baseEntity}`);
|
|
77
|
-
}
|
|
78
|
-
entityMap[baseEntity] = ((_a = json["baseEntities"]) !== null && _a !== void 0 ? _a : []).map(
|
|
79
|
-
// REVIEW: Needs to be fixed after audit column type conversion
|
|
80
|
-
(e) => entityFromJsonMappings[baseEntity](e));
|
|
81
|
-
if (json["relatedEntities"]) {
|
|
82
|
-
const relatedEntities = json["relatedEntities"];
|
|
83
|
-
for (const entityName in relatedEntities) {
|
|
84
|
-
parseEntities(
|
|
85
|
-
// @ts-ignore
|
|
86
|
-
relatedEntities[entityName], entityName, entityMap);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return entityMap;
|
|
90
|
-
}
|
|
91
60
|
exports.entityEnumToEntityModel = {
|
|
92
61
|
[entity_utils_interface_1.EntityEnum.PROJECT]: project_entity_model_1.ProjectEntityModel.fromEntity,
|
|
93
62
|
[entity_utils_interface_1.EntityEnum.CLIENT]: client_entity_model_1.ClientEntityModel.fromEntity,
|
|
@@ -107,13 +76,45 @@ exports.entityEnumToEntityModel = {
|
|
|
107
76
|
[entity_utils_interface_1.EntityEnum.TASK]: task_entity_model_1.TaskEntityModel.fromEntity,
|
|
108
77
|
[entity_utils_interface_1.EntityEnum.BILLING_TIMESHEET]: billing_timesheet_entity_model_1.BillingTimesheetEntityModel.fromEntity,
|
|
109
78
|
[entity_utils_interface_1.EntityEnum.TIMESHEET]: timesheet_entity_model_1.TimesheetEntityModel.fromEntity,
|
|
110
|
-
[entity_utils_interface_1.EntityEnum.
|
|
79
|
+
[entity_utils_interface_1.EntityEnum.COUNTRY]: country_entity_model_1.CountryEntityModel.fromApiEntity,
|
|
80
|
+
[entity_utils_interface_1.EntityEnum.ADDRESS_BOOK]: address_book_model_1.AddressBookEntityModel.fromEntity,
|
|
111
81
|
};
|
|
112
|
-
function
|
|
82
|
+
function entityMapToModels(entityMap) {
|
|
83
|
+
for (const entityName in entityMap) {
|
|
84
|
+
if (!(entityName in exports.entityEnumToEntityModel)) {
|
|
85
|
+
throw new Error(`Unknown entity: ${entityName}`);
|
|
86
|
+
}
|
|
87
|
+
entityMap[entityName] = entityMap[entityName].map((entity) =>
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
exports.entityEnumToEntityModel[entityName](entity));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function parseEntities(json, baseEntity, entityMap) {
|
|
113
93
|
var _a;
|
|
114
94
|
if (!(baseEntity in exports.entityEnumToEntityModel)) {
|
|
115
95
|
throw new Error(`Unknown entity: ${baseEntity}`);
|
|
116
96
|
}
|
|
97
|
+
entityMap[baseEntity] = ((_a = json["baseEntities"]) !== null && _a !== void 0 ? _a : []).map(
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
(e) => exports.entityEnumToEntityModel[baseEntity](e));
|
|
100
|
+
if (json["relatedEntities"]) {
|
|
101
|
+
const relatedEntities = json["relatedEntities"];
|
|
102
|
+
for (const entityName in relatedEntities) {
|
|
103
|
+
parseEntities(
|
|
104
|
+
// @ts-ignore
|
|
105
|
+
relatedEntities[entityName], entityName, entityMap);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return entityMap;
|
|
109
|
+
}
|
|
110
|
+
function entityMapToEntityIndexMap(entityMap, entityRelationsFor) {
|
|
111
|
+
entityMapToModels(entityMap);
|
|
112
|
+
const entityIndexMap = mapToIndex(entityMap);
|
|
113
|
+
populateRelationsFor(entityIndexMap, entityRelationsFor);
|
|
114
|
+
return entityIndexMap;
|
|
115
|
+
}
|
|
116
|
+
function parseEntitiesWithoutModels(json, baseEntity, entityMap = {}) {
|
|
117
|
+
var _a;
|
|
117
118
|
entityMap[baseEntity] = ((_a = json["baseEntities"]) !== null && _a !== void 0 ? _a : []);
|
|
118
119
|
if (json["relatedEntities"]) {
|
|
119
120
|
const relatedEntities = json["relatedEntities"];
|
|
@@ -125,3 +126,88 @@ function parseEntitiesWithoutModels(json, baseEntity, entityMap = {}) {
|
|
|
125
126
|
}
|
|
126
127
|
return entityMap;
|
|
127
128
|
}
|
|
129
|
+
function removeEntityById(entityIndexMap, entity, id) {
|
|
130
|
+
if (entityIndexMap[entity]) {
|
|
131
|
+
delete entityIndexMap[entity][id];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
class EntityModelRelationHelper {
|
|
135
|
+
constructor(entityMap) {
|
|
136
|
+
this.entityMap = entityMap;
|
|
137
|
+
this.entityModelMap = {};
|
|
138
|
+
this.entityModelIndexMap = {};
|
|
139
|
+
this.init();
|
|
140
|
+
}
|
|
141
|
+
init() {
|
|
142
|
+
this.toEntityModelMap();
|
|
143
|
+
this.toEntityModelIndexMap();
|
|
144
|
+
}
|
|
145
|
+
toEntityModelMap() {
|
|
146
|
+
for (const entityName in this.entityMap) {
|
|
147
|
+
if (!(entityName in exports.entityEnumToEntityModel)) {
|
|
148
|
+
throw new Error(`Unknown entity: ${entityName}`);
|
|
149
|
+
}
|
|
150
|
+
this.entityModelMap[entityName] = this.entityMap[entityName].map((entity) =>
|
|
151
|
+
// @ts-ignore
|
|
152
|
+
exports.entityEnumToEntityModel[entityName](entity));
|
|
153
|
+
}
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
fromEntityToEntityModel(entity, entityEnum) {
|
|
157
|
+
if (!(entityEnum in exports.entityEnumToEntityModel)) {
|
|
158
|
+
throw new Error(`Unknown entity: ${entityEnum}`);
|
|
159
|
+
}
|
|
160
|
+
return exports.entityEnumToEntityModel[entityEnum](entity);
|
|
161
|
+
}
|
|
162
|
+
toEntityModelIndexMap() {
|
|
163
|
+
this.entityModelIndexMap = Object.keys(this.entityModelMap).reduce((acc, key) => {
|
|
164
|
+
// @ts-ignore
|
|
165
|
+
acc[key] = this.entityModelMap[key].reduce((innerAcc, entity) => {
|
|
166
|
+
innerAcc[entity.id] = entity;
|
|
167
|
+
return innerAcc;
|
|
168
|
+
}, {});
|
|
169
|
+
return acc;
|
|
170
|
+
}, {});
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
populateRelationsByEntityEnums(entityEnums) {
|
|
174
|
+
entityEnums.forEach((entityEnum) => {
|
|
175
|
+
this.populateRelationsByEntityEnum(entityEnum);
|
|
176
|
+
});
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
populateRelationsByEntityEnum(entityEnum) {
|
|
180
|
+
for (const key of Object.keys(this.entityModelIndexMap[entityEnum] || {})) {
|
|
181
|
+
const entityModel = this.entityModelIndexMap[entityEnum][key];
|
|
182
|
+
entityModel.populateRelationsByIndex(this.entityModelIndexMap);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
populateRelationsByEntityModel(entityModel) {
|
|
186
|
+
entityModel.populateRelationsByIndex(this.entityModelIndexMap);
|
|
187
|
+
}
|
|
188
|
+
addEntityModel(entityModel, config = { populateRelations: false }) {
|
|
189
|
+
const entityEnum = entityModel.entityName;
|
|
190
|
+
this.entityModelIndexMap[entityEnum] = this.entityModelIndexMap[entityEnum] || {};
|
|
191
|
+
// @ts-ignore
|
|
192
|
+
this.entityModelIndexMap[entityEnum][entityModel.id] = entityModel;
|
|
193
|
+
if (config.populateRelations) {
|
|
194
|
+
this.populateRelationsByEntityModel(entityModel);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
addEntity(entity, entityEnum, config = { populateRelations: false }) {
|
|
198
|
+
if (!(entityEnum in exports.entityEnumToEntityModel)) {
|
|
199
|
+
throw new Error(`Unknown entity: ${entityEnum}`);
|
|
200
|
+
}
|
|
201
|
+
this.addEntityModel(this.fromEntityToEntityModel(entity, entityEnum), config);
|
|
202
|
+
}
|
|
203
|
+
updateEntityModel(entityModel, config = { populateRelations: false }) {
|
|
204
|
+
const entityEnum = entityModel.entityName;
|
|
205
|
+
this.entityModelIndexMap[entityEnum] = this.entityModelIndexMap[entityEnum] || {};
|
|
206
|
+
// @ts-ignore
|
|
207
|
+
this.entityModelIndexMap[entityEnum][entityModel.id] = entityModel;
|
|
208
|
+
if (config.populateRelations) {
|
|
209
|
+
this.populateRelationsByEntityModel(entityModel);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.EntityModelRelationHelper = EntityModelRelationHelper;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type ArrayComparisonCategory<T> = {
|
|
2
|
+
unchanged: T[];
|
|
3
|
+
added: T[];
|
|
4
|
+
updated: T[];
|
|
5
|
+
deleted: {
|
|
6
|
+
[x: string]: T[keyof T];
|
|
7
|
+
}[];
|
|
8
|
+
notFound: {
|
|
9
|
+
[x: string]: T[keyof T];
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
export declare class ArrayComparisonCategorizer<T> {
|
|
13
|
+
private incomingArray;
|
|
14
|
+
private existingArray;
|
|
15
|
+
private keyProperty;
|
|
16
|
+
private arrayComparisonCategory;
|
|
17
|
+
constructor(incomingArray: T[] | undefined, existingArray: T[] | undefined, keyProperty: keyof T);
|
|
18
|
+
private get existingMap();
|
|
19
|
+
private isExistingItem;
|
|
20
|
+
private isMarkForDeletion;
|
|
21
|
+
private isIdentifierPresent;
|
|
22
|
+
compare(): ArrayComparisonCategory<T>;
|
|
23
|
+
get category(): ArrayComparisonCategory<T> | null;
|
|
24
|
+
merge(): T[];
|
|
25
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrayComparisonCategorizer = void 0;
|
|
4
|
+
function deepEqual(a, b) {
|
|
5
|
+
if (a === b)
|
|
6
|
+
return true;
|
|
7
|
+
if (a == null || b == null)
|
|
8
|
+
return false;
|
|
9
|
+
if (typeof a !== typeof b)
|
|
10
|
+
return false;
|
|
11
|
+
if (typeof a !== "object")
|
|
12
|
+
return a === b;
|
|
13
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
14
|
+
return false;
|
|
15
|
+
if (Array.isArray(a)) {
|
|
16
|
+
if (a.length !== b.length)
|
|
17
|
+
return false;
|
|
18
|
+
return a.every((v, i) => deepEqual(v, b[i]));
|
|
19
|
+
}
|
|
20
|
+
const keysA = Object.keys(a).sort();
|
|
21
|
+
const keysB = Object.keys(b).sort();
|
|
22
|
+
if (keysA.length !== keysB.length)
|
|
23
|
+
return false;
|
|
24
|
+
return keysA.every((key) => deepEqual(a[key], b[key]));
|
|
25
|
+
}
|
|
26
|
+
class ArrayComparisonCategorizer {
|
|
27
|
+
constructor(incomingArray = [], existingArray = [], keyProperty) {
|
|
28
|
+
this.arrayComparisonCategory = null;
|
|
29
|
+
this.incomingArray = [...incomingArray];
|
|
30
|
+
this.existingArray = [...existingArray];
|
|
31
|
+
this.keyProperty = keyProperty;
|
|
32
|
+
}
|
|
33
|
+
get existingMap() {
|
|
34
|
+
return new Map(this.existingArray.filter((item) => item[this.keyProperty] !== undefined).map((item) => [item[this.keyProperty], item]));
|
|
35
|
+
}
|
|
36
|
+
isExistingItem(incomingItem, existingMap) {
|
|
37
|
+
return existingMap.has(incomingItem[this.keyProperty]);
|
|
38
|
+
}
|
|
39
|
+
isMarkForDeletion(incomingItem) {
|
|
40
|
+
const onlyIdentifierPresent = Object.keys(incomingItem).length === 1;
|
|
41
|
+
return this.isIdentifierPresent(incomingItem) && onlyIdentifierPresent;
|
|
42
|
+
}
|
|
43
|
+
isIdentifierPresent(incomingItem) {
|
|
44
|
+
return incomingItem[this.keyProperty] !== undefined && incomingItem[this.keyProperty] !== null;
|
|
45
|
+
}
|
|
46
|
+
compare() {
|
|
47
|
+
const existingMap = this.existingMap;
|
|
48
|
+
const unchanged = [];
|
|
49
|
+
const added = [];
|
|
50
|
+
const updated = [];
|
|
51
|
+
const deleted = [];
|
|
52
|
+
const notFound = [];
|
|
53
|
+
for (const incomingItem of this.incomingArray) {
|
|
54
|
+
const isIdentifierPresent = this.isIdentifierPresent(incomingItem);
|
|
55
|
+
const isMarkForDeletion = isIdentifierPresent && this.isMarkForDeletion(incomingItem);
|
|
56
|
+
const isExistingItem = isIdentifierPresent && this.isExistingItem(incomingItem, existingMap);
|
|
57
|
+
const existingItem = isExistingItem ? existingMap.get(incomingItem[this.keyProperty]) : null;
|
|
58
|
+
if (isMarkForDeletion) {
|
|
59
|
+
deleted.push({ [this.keyProperty]: incomingItem[this.keyProperty] });
|
|
60
|
+
}
|
|
61
|
+
else if (!isIdentifierPresent && !isExistingItem) {
|
|
62
|
+
added.push(incomingItem);
|
|
63
|
+
}
|
|
64
|
+
else if (isExistingItem && isIdentifierPresent) {
|
|
65
|
+
if (deepEqual(incomingItem, existingItem)) {
|
|
66
|
+
unchanged.push(incomingItem);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
updated.push(incomingItem);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
notFound.push({ [this.keyProperty]: incomingItem[this.keyProperty] });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const result = {
|
|
77
|
+
unchanged,
|
|
78
|
+
added,
|
|
79
|
+
updated,
|
|
80
|
+
deleted,
|
|
81
|
+
notFound
|
|
82
|
+
};
|
|
83
|
+
this.arrayComparisonCategory = result;
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
get category() {
|
|
87
|
+
return this.arrayComparisonCategory;
|
|
88
|
+
}
|
|
89
|
+
merge() {
|
|
90
|
+
if (!this.arrayComparisonCategory) {
|
|
91
|
+
throw new Error("ArrayComparisonCategory is not computed yet. Call compare() first.");
|
|
92
|
+
}
|
|
93
|
+
const changes = this.arrayComparisonCategory;
|
|
94
|
+
let newState = this.existingArray.filter(this.isIdentifierPresent.bind(this));
|
|
95
|
+
// Remove deleted items
|
|
96
|
+
const deletedIds = new Set(changes.deleted.map((d) => d[this.keyProperty]));
|
|
97
|
+
newState = newState.filter((item) => !deletedIds.has(item[this.keyProperty]));
|
|
98
|
+
// Update items
|
|
99
|
+
for (let i = 0; i < newState.length; i++) {
|
|
100
|
+
const item = newState[i];
|
|
101
|
+
const updatedItem = changes.updated.find((u) => u[this.keyProperty] === item[this.keyProperty]);
|
|
102
|
+
if (updatedItem) {
|
|
103
|
+
newState[i] = updatedItem;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Get Max Id
|
|
107
|
+
const existingWithId = this.existingArray.filter(this.isIdentifierPresent.bind(this));
|
|
108
|
+
const originalMaxId = existingWithId.length > 0
|
|
109
|
+
? Math.max(...existingWithId.map((item) => item[this.keyProperty]))
|
|
110
|
+
: 0;
|
|
111
|
+
// Add new items with new identifier
|
|
112
|
+
let currentMaxId = originalMaxId;
|
|
113
|
+
for (const item of changes.added) {
|
|
114
|
+
const id = ++currentMaxId;
|
|
115
|
+
newState.push(Object.assign(Object.assign({}, item), { [this.keyProperty]: id }));
|
|
116
|
+
}
|
|
117
|
+
return newState;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.ArrayComparisonCategorizer = ArrayComparisonCategorizer;
|
|
121
|
+
// function categorizeChanges<T extends Item>(
|
|
122
|
+
// incoming: T[],
|
|
123
|
+
// existing: T[]
|
|
124
|
+
// ): {
|
|
125
|
+
// unchanged: T[];
|
|
126
|
+
// added: T[];
|
|
127
|
+
// updated: T[];
|
|
128
|
+
// deleted: { id: number }[];
|
|
129
|
+
// notFound: { id: number }[];
|
|
130
|
+
// } {
|
|
131
|
+
// console.log("Categorizing changes between incoming and existing items");
|
|
132
|
+
// console.log("Incoming items:", incoming);
|
|
133
|
+
// console.log("Existing items:", existing);
|
|
134
|
+
// const existingMap = new Map<number, T>(existing.filter((item) => item.id !== undefined).map((item) => [item.id!, item]));
|
|
135
|
+
// const incomingIds = new Set<number>(incoming.filter((item) => item.id !== undefined).map((item) => item.id!));
|
|
136
|
+
// const deleted: { id: number }[] = [];
|
|
137
|
+
// const notFound: { id: number }[] = [];
|
|
138
|
+
// const unchanged: T[] = [];
|
|
139
|
+
// const updated: T[] = [];
|
|
140
|
+
// const added: T[] = [];
|
|
141
|
+
// for (const item of incoming) {
|
|
142
|
+
// if (item.id === undefined) {
|
|
143
|
+
// added.push(item);
|
|
144
|
+
// continue;
|
|
145
|
+
// }
|
|
146
|
+
// const id = item.id;
|
|
147
|
+
// if (Object.keys(item).length === 1) {
|
|
148
|
+
// deleted.push({ id });
|
|
149
|
+
// continue;
|
|
150
|
+
// }
|
|
151
|
+
// if (!existingMap.has(id)) {
|
|
152
|
+
// added.push(item);
|
|
153
|
+
// continue;
|
|
154
|
+
// }
|
|
155
|
+
// const existingItem = existingMap.get(id)!;
|
|
156
|
+
// if (deepEqual(item, existingItem)) {
|
|
157
|
+
// unchanged.push(item);
|
|
158
|
+
// } else {
|
|
159
|
+
// updated.push(item);
|
|
160
|
+
// }
|
|
161
|
+
// }
|
|
162
|
+
// for (const [id] of existingMap) {
|
|
163
|
+
// if (!incomingIds.has(id)) {
|
|
164
|
+
// notFound.push({ id });
|
|
165
|
+
// }
|
|
166
|
+
// }
|
|
167
|
+
// return { unchanged, added, updated, deleted, notFound };
|
|
168
|
+
// }
|
package/dist/src/utils/index.js
CHANGED
|
@@ -19,3 +19,4 @@ __exportStar(require("./helper.fn.util"), exports);
|
|
|
19
19
|
__exportStar(require("./models/date-code.model.util"), exports);
|
|
20
20
|
__exportStar(require("./string.util"), exports);
|
|
21
21
|
__exportStar(require("./entity.flow.util"), exports);
|
|
22
|
+
__exportStar(require("./array.util"), exports);
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
class ObjectComparator {
|
|
3
|
+
constructor(incoming, existing) {
|
|
4
|
+
this.incoming = incoming;
|
|
5
|
+
this.existing = existing;
|
|
6
|
+
}
|
|
7
|
+
compare() {
|
|
8
|
+
return this.deepDiff(this.incoming, this.existing);
|
|
9
|
+
}
|
|
10
|
+
deepDiff(a, b) {
|
|
11
|
+
// Handle null/undefined cases
|
|
12
|
+
if (a == null && b == null) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
if (a == null || b == null) {
|
|
16
|
+
return a;
|
|
17
|
+
}
|
|
18
|
+
// Handle primitives (loose equality)
|
|
19
|
+
if (typeof a !== "object") {
|
|
20
|
+
return a == b ? undefined : a;
|
|
21
|
+
}
|
|
22
|
+
// a is object or array
|
|
23
|
+
if (Array.isArray(a)) {
|
|
24
|
+
// Handle as array
|
|
25
|
+
const diffArr = new Array(a.length);
|
|
26
|
+
let hasDiff = false;
|
|
27
|
+
for (let i = 0; i < a.length; i++) {
|
|
28
|
+
const subB = Array.isArray(b) && i < b.length ? b[i] : undefined;
|
|
29
|
+
const subDiff = this.deepDiff(a[i], subB);
|
|
30
|
+
if (subDiff !== undefined) {
|
|
31
|
+
diffArr[i] = subDiff;
|
|
32
|
+
hasDiff = true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return hasDiff ? diffArr : undefined;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// Handle as object
|
|
39
|
+
const diff = {};
|
|
40
|
+
let hasDiff = false;
|
|
41
|
+
for (const key of Object.keys(a)) {
|
|
42
|
+
const subDiff = this.deepDiff(a[key], b === null || b === void 0 ? void 0 : b[key]);
|
|
43
|
+
if (subDiff !== undefined) {
|
|
44
|
+
diff[key] = subDiff;
|
|
45
|
+
hasDiff = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return hasDiff ? diff : undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// // Comprehensive Usage Examples
|
|
53
|
+
// // Example 1: Simple object with primitive differences
|
|
54
|
+
// console.log("Example 1: Simple object");
|
|
55
|
+
// const incoming1 = { name: "Alice", age: 30, city: "New York" };
|
|
56
|
+
// const existing1 = { name: "Bob", age: 30, city: "Boston" };
|
|
57
|
+
// const comparator1 = new ObjectComparator(incoming1, existing1);
|
|
58
|
+
// console.log(comparator1.compare()); // Output: { name: 'Alice', city: 'New York' }
|
|
59
|
+
// // Example 2: Nested objects
|
|
60
|
+
// console.log("Example 2: Nested objects");
|
|
61
|
+
// const incoming2 = {
|
|
62
|
+
// user: { id: 1, profile: { email: "alice@example.com", phone: "123-456" } },
|
|
63
|
+
// settings: { theme: "dark", notifications: true },
|
|
64
|
+
// };
|
|
65
|
+
// const existing2 = {
|
|
66
|
+
// user: { id: 1, profile: { email: "bob@example.com" } },
|
|
67
|
+
// settings: { theme: "light" },
|
|
68
|
+
// };
|
|
69
|
+
// const comparator2 = new ObjectComparator(incoming2, existing2);
|
|
70
|
+
// console.log(comparator2.compare());
|
|
71
|
+
// // Output: {
|
|
72
|
+
// // user: { profile: { email: 'alice@example.com', phone: '123-456' } },
|
|
73
|
+
// // settings: { theme: 'dark', notifications: true }
|
|
74
|
+
// // }
|
|
75
|
+
// // Example 3: Array of primitives
|
|
76
|
+
// console.log("Example 3: Array of primitives");
|
|
77
|
+
// const incoming3 = { scores: [95, 87, 100] };
|
|
78
|
+
// const existing3 = { scores: [80, 87, 90] };
|
|
79
|
+
// const comparator3 = new ObjectComparator(incoming3, existing3);
|
|
80
|
+
// console.log(comparator3.compare()); // Output: { scores: [95, undefined, 100] }
|
|
81
|
+
// // Example 4: Array of objects
|
|
82
|
+
// console.log("Example 4: Array of objects");
|
|
83
|
+
// const incoming4 = {
|
|
84
|
+
// items: [
|
|
85
|
+
// { id: 1, name: "Item A", price: 10 },
|
|
86
|
+
// { id: 2, name: "Item B", price: 20 },
|
|
87
|
+
// { id: 3, name: "Item C", price: 30 },
|
|
88
|
+
// ],
|
|
89
|
+
// };
|
|
90
|
+
// const existing4 = {
|
|
91
|
+
// items: [
|
|
92
|
+
// { id: 1, name: "Item A", price: 15 },
|
|
93
|
+
// { id: 2, name: "Item X", price: 20 },
|
|
94
|
+
// ],
|
|
95
|
+
// };
|
|
96
|
+
// const comparator4 = new ObjectComparator(incoming4, existing4);
|
|
97
|
+
// console.log(comparator4.compare());
|
|
98
|
+
// // Output: {
|
|
99
|
+
// // items: [
|
|
100
|
+
// // { price: 10 },
|
|
101
|
+
// // { name: 'Item B' },
|
|
102
|
+
// // { id: 3, name: 'Item C', price: 30 }
|
|
103
|
+
// // ]
|
|
104
|
+
// // }
|
|
105
|
+
// // Example 5: Mixed structure with missing properties and nulls
|
|
106
|
+
// console.log("Example 5: Mixed with nulls and missing");
|
|
107
|
+
// const incoming5 = {
|
|
108
|
+
// data: {
|
|
109
|
+
// value: null,
|
|
110
|
+
// list: [1, 2, { nested: "hello" }],
|
|
111
|
+
// extra: "new",
|
|
112
|
+
// },
|
|
113
|
+
// };
|
|
114
|
+
// const existing5 = {
|
|
115
|
+
// data: {
|
|
116
|
+
// value: 42,
|
|
117
|
+
// list: [1, 3],
|
|
118
|
+
// },
|
|
119
|
+
// };
|
|
120
|
+
// const comparator5 = new ObjectComparator(incoming5, existing5);
|
|
121
|
+
// console.log(comparator5.compare());
|
|
122
|
+
// // Output: {
|
|
123
|
+
// // data: {
|
|
124
|
+
// // value: null,
|
|
125
|
+
// // list: [undefined, 2, { nested: 'hello' }],
|
|
126
|
+
// // extra: 'new'
|
|
127
|
+
// // }
|
|
128
|
+
// // }
|
|
129
|
+
// // Example 6: No differences
|
|
130
|
+
// console.log("Example 6: No differences");
|
|
131
|
+
// const incoming6 = { a: 1, b: { c: [true] } };
|
|
132
|
+
// const existing6 = { a: 1, b: { c: [true] } };
|
|
133
|
+
// const comparator6 = new ObjectComparator(incoming6, existing6);
|
|
134
|
+
// console.log(comparator6.compare()); // Output: {}
|