diff --git a/package-lock.json b/package-lock.json index 55b86cc0..0e6d5852 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,7 @@ "@vality/machinegun-proto": "1.0.0", "@vality/magista-proto": "2.0.2-28d11b9.0", "@vality/ng-core": "17.2.1-pr-61-d842667.0", + "@vality/ng-thrift": "17.0.1-pr-5-2ce0f11.0", "@vality/payout-manager-proto": "2.0.1-eb4091a.0", "@vality/repairer-proto": "2.0.2-07b73e9.0", "@vality/scrooge-proto": "0.1.1-9ce7fc6.0", @@ -6481,6 +6482,38 @@ "utility-types": "^3.0.0" } }, + "node_modules/@vality/ng-thrift": { + "version": "17.0.1-pr-5-2ce0f11.0", + "resolved": "https://registry.npmjs.org/@vality/ng-thrift/-/ng-thrift-17.0.1-pr-5-2ce0f11.0.tgz", + "integrity": "sha512-LC/6uzTKu2sgbus2KwGqdzt9r/6JPkRJbkvAByq2fh5cu/RUMJTTQPnrhDDCp0Mc5IuOzUScX+Cl9qFwBXoJcQ==", + "dependencies": { + "tslib": "^2.3.0", + "yaml": "^2.4.2" + }, + "peerDependencies": { + "@angular/cdk": "^17.2.0", + "@angular/common": "^17.2.0", + "@angular/core": "^17.2.0", + "@angular/material": "^17.2.0", + "@types/lodash-es": "^4.0.0", + "@vality/ng-core": "^17.2.1-a6a2910.0", + "@vality/thrift-ts": "^2.4.1-8ad5123.0", + "lodash-es": "^4.0.0", + "rxjs": "^7.0.0", + "utility-types": "^3.0.0" + } + }, + "node_modules/@vality/ng-thrift/node_modules/yaml": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.4.2.tgz", + "integrity": "sha512-B3VqDZ+JAg1nZpaEmWtTXUlBneoGx6CPM9b0TENK6aoSu5t73dItudwdgmi6tHlIZZId4dZ9skcAQ2UbcyAeVA==", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/@vality/payout-manager-proto": { "version": "2.0.1-eb4091a.0", "resolved": "https://registry.npmjs.org/@vality/payout-manager-proto/-/payout-manager-proto-2.0.1-eb4091a.0.tgz", diff --git a/package.json b/package.json index aba370d7..43638a58 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "@vality/machinegun-proto": "1.0.0", "@vality/magista-proto": "2.0.2-28d11b9.0", "@vality/ng-core": "17.2.1-pr-61-d842667.0", + "@vality/ng-thrift": "17.0.1-pr-5-2ce0f11.0", "@vality/payout-manager-proto": "2.0.1-eb4091a.0", "@vality/repairer-proto": "2.0.2-07b73e9.0", "@vality/scrooge-proto": "0.1.1-9ce7fc6.0", diff --git a/src/app/api/domain-config/stores/domain-store.service.ts b/src/app/api/domain-config/stores/domain-store.service.ts index 1c0588c8..93a9b747 100644 --- a/src/app/api/domain-config/stores/domain-store.service.ts +++ b/src/app/api/domain-config/stores/domain-store.service.ts @@ -3,11 +3,11 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { Domain, DomainObject, Reference } from '@vality/domain-proto/domain'; import { Commit, Snapshot, Version } from '@vality/domain-proto/domain_config'; import { NotifyLogService, handleError, inProgressFrom, progressTo } from '@vality/ng-core'; +import { getUnionKey } from '@vality/ng-thrift'; import isEqual from 'lodash-es/isEqual'; import { BehaviorSubject, defer, Observable, of, ReplaySubject, filter, combineLatest } from 'rxjs'; import { map, shareReplay, startWith, switchMap, take, tap } from 'rxjs/operators'; -import { getUnionKey } from '../../../../utils'; import { DomainSecretService } from '../../../shared/services'; import { RepositoryService } from '../repository.service'; diff --git a/src/app/sections/chargebacks/chargebacks.component.html b/src/app/sections/chargebacks/chargebacks.component.html index 13a6ee0d..bb82293f 100644 --- a/src/app/sections/chargebacks/chargebacks.component.html +++ b/src/app/sections/chargebacks/chargebacks.component.html @@ -17,7 +17,7 @@ Statuses - {{ status | keyTitle | titlecase }} + {{ status | ngtKeyTitle | titlecase }} @@ -25,7 +25,7 @@ Stages - {{ stage | keyTitle | titlecase }} + {{ stage | ngtKeyTitle | titlecase }} @@ -33,7 +33,7 @@ Categories - {{ category | keyTitle | titlecase }} + {{ category | ngtKeyTitle | titlecase }} diff --git a/src/app/sections/chargebacks/chargebacks.component.ts b/src/app/sections/chargebacks/chargebacks.component.ts index 7ce2b728..7e1462ae 100644 --- a/src/app/sections/chargebacks/chargebacks.component.ts +++ b/src/app/sections/chargebacks/chargebacks.component.ts @@ -17,6 +17,7 @@ import { debounceTimeWithFirst, countChanged, } from '@vality/ng-core'; +import { createUnion } from '@vality/ng-thrift'; import { endOfDay } from 'date-fns'; import { filter } from 'rxjs'; import { map, shareReplay } from 'rxjs/operators'; @@ -28,7 +29,6 @@ import { CHARGEBACK_CATEGORIES, } from '@cc/app/api/fistful-stat'; -import { createUnion } from '../../../utils'; import { ChangeChargebacksStatusDialogComponent } from '../../shared/components/change-chargebacks-status-dialog'; import { DATE_RANGE_DAYS, DEBOUNCE_TIME_MS } from '../../tokens'; diff --git a/src/app/sections/chargebacks/chargebacks.module.ts b/src/app/sections/chargebacks/chargebacks.module.ts index e8fc0d8c..41ce7aa7 100644 --- a/src/app/sections/chargebacks/chargebacks.module.ts +++ b/src/app/sections/chargebacks/chargebacks.module.ts @@ -18,12 +18,13 @@ import { DialogModule, FileUploadModule, } from '@vality/ng-core'; +import { ThriftPipesModule } from '@vality/ng-thrift'; import { MagistaThriftFormComponent } from '@cc/app/shared/components/thrift-api-crud'; -import { PageLayoutModule, ShopFieldModule, ThriftPipesModule } from '../../shared'; +import { PageLayoutModule, ShopFieldModule } from '../../shared'; import { MerchantFieldModule } from '../../shared/components/merchant-field'; -import { MetadataFormModule } from '../../shared/components/metadata-form'; +import { ThriftFormModule } from '../../shared/components/metadata-form'; import { DomainThriftFormComponent } from '../../shared/components/thrift-api-crud/domain/domain-thrift-form'; import { ChargebacksRoutingModule } from './chargebacks-routing.module'; @@ -49,7 +50,7 @@ import { CreateChargebacksByFileDialogComponent } from './components/create-char MerchantFieldModule, ShopFieldModule, InputFieldModule, - MetadataFormModule, + ThriftFormModule, MagistaThriftFormComponent, SelectFieldModule, MatFormFieldModule, diff --git a/src/app/sections/chargebacks/components/chargebacks-table/chargebacks-table.component.ts b/src/app/sections/chargebacks/components/chargebacks-table/chargebacks-table.component.ts index 736af3d7..370edbce 100644 --- a/src/app/sections/chargebacks/components/chargebacks-table/chargebacks-table.component.ts +++ b/src/app/sections/chargebacks/components/chargebacks-table/chargebacks-table.component.ts @@ -2,9 +2,9 @@ import { Component, Input, Output, EventEmitter } from '@angular/core'; import { InvoicePaymentChargebackStatus } from '@vality/magista-proto/internal/proto/domain'; import { StatChargeback } from '@vality/magista-proto/magista'; import { LoadOptions, Column, TagColumn } from '@vality/ng-core'; +import { getUnionKey } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; -import { getUnionKey } from '../../../../../utils'; import { AmountCurrencyService } from '../../../../shared/services'; @Component({ diff --git a/src/app/sections/chargebacks/components/create-chargebacks-by-file-dialog/create-chargebacks-by-file-dialog.component.ts b/src/app/sections/chargebacks/components/create-chargebacks-by-file-dialog/create-chargebacks-by-file-dialog.component.ts index 1aee1940..48546077 100644 --- a/src/app/sections/chargebacks/components/create-chargebacks-by-file-dialog/create-chargebacks-by-file-dialog.component.ts +++ b/src/app/sections/chargebacks/components/create-chargebacks-by-file-dialog/create-chargebacks-by-file-dialog.component.ts @@ -11,12 +11,13 @@ import { forkJoinToResult, Column, } from '@vality/ng-core'; +import { getUnionKey } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; import { BehaviorSubject, combineLatest } from 'rxjs'; import { switchMap, map, shareReplay, tap, startWith } from 'rxjs/operators'; import { InvoicingService } from '@cc/app/api/payment-processing'; -import { parseCsv, unifyCsvItems, getUnionKey } from '@cc/utils'; +import { parseCsv, unifyCsvItems } from '@cc/utils'; import { AmountCurrencyService } from '../../../../shared/services'; diff --git a/src/app/sections/claim/claim.component.html b/src/app/sections/claim/claim.component.html index c9037fe9..f47a98c7 100644 --- a/src/app/sections/claim/claim.component.html +++ b/src/app/sections/claim/claim.component.html @@ -1,7 +1,7 @@ - {{ - claim.status | ccUnionKey | keyTitle | titlecase + {{ + claim.status | ngtUnionKey | ngtKeyTitle | titlecase }} @@ -32,11 +32,11 @@ {{ - status | keyTitle | titlecase + status | ngtKeyTitle | titlecase }} diff --git a/src/app/sections/claim/components/change-status-dialog/change-status-dialog.component.ts b/src/app/sections/claim/components/change-status-dialog/change-status-dialog.component.ts index 85fd5259..3fe7fee6 100644 --- a/src/app/sections/claim/components/change-status-dialog/change-status-dialog.component.ts +++ b/src/app/sections/claim/components/change-status-dialog/change-status-dialog.component.ts @@ -9,11 +9,11 @@ import { inProgressFrom, progressTo, } from '@vality/ng-core'; +import { getUnionKey } from '@vality/ng-thrift'; import { BehaviorSubject, Observable } from 'rxjs'; import { ClaimManagementService } from '@cc/app/api/claim-management'; import { AllowedClaimStatusesService } from '@cc/app/sections/claim/services/allowed-claim-statuses.service'; -import { getUnionKey } from '@cc/utils'; @Component({ selector: 'cc-change-status-dialog', diff --git a/src/app/sections/claim/components/create-shop-dialog/create-shop-dialog.component.ts b/src/app/sections/claim/components/create-shop-dialog/create-shop-dialog.component.ts index d9a7105b..43dcb8a8 100644 --- a/src/app/sections/claim/components/create-shop-dialog/create-shop-dialog.component.ts +++ b/src/app/sections/claim/components/create-shop-dialog/create-shop-dialog.component.ts @@ -22,11 +22,12 @@ import { NotifyLogService, progressTo, } from '@vality/ng-core'; +import { isTypeWithAliases } from '@vality/ng-thrift'; import { of, BehaviorSubject } from 'rxjs'; import { first } from 'rxjs/operators'; import short from 'short-uuid'; -import { MetadataFormExtension, isTypeWithAliases } from '@cc/app/shared/components/metadata-form'; +import { MetadataFormExtension } from '@cc/app/shared/components/metadata-form'; import { ClaimManagementService } from '../../../../api/claim-management'; import { DomainStoreService } from '../../../../api/domain-config'; diff --git a/src/app/sections/claim/components/modification-unit-timeline-item/modification-unit-timeline-item.component.html b/src/app/sections/claim/components/modification-unit-timeline-item/modification-unit-timeline-item.component.html index 9b381ddf..bd3cc8fd 100644 --- a/src/app/sections/claim/components/modification-unit-timeline-item/modification-unit-timeline-item.component.html +++ b/src/app/sections/claim/components/modification-unit-timeline-item/modification-unit-timeline-item.component.html @@ -6,7 +6,7 @@
@@ -34,7 +34,7 @@
- {{ name | keyTitle | titlecase }} + {{ name | ngtKeyTitle | titlecase }} diff --git a/src/app/sections/claim/components/status-modification-timeline-item/status-modification-timeline-item.component.ts b/src/app/sections/claim/components/status-modification-timeline-item/status-modification-timeline-item.component.ts index e9e8b6bf..a064e12d 100644 --- a/src/app/sections/claim/components/status-modification-timeline-item/status-modification-timeline-item.component.ts +++ b/src/app/sections/claim/components/status-modification-timeline-item/status-modification-timeline-item.component.ts @@ -1,7 +1,6 @@ import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Claim, ClaimStatus, ModificationUnit } from '@vality/domain-proto/claim_management'; - -import { getUnionKey, getUnionValue } from '@cc/utils'; +import { getUnionKey, getUnionValue } from '@vality/ng-thrift'; import { CLAIM_STATUS_COLOR } from '../../types/claim-status-color'; diff --git a/src/app/sections/claim/utils/get-modification-name.ts b/src/app/sections/claim/utils/get-modification-name.ts index ce4b1f63..8693433b 100644 --- a/src/app/sections/claim/utils/get-modification-name.ts +++ b/src/app/sections/claim/utils/get-modification-name.ts @@ -1,8 +1,7 @@ import { Modification } from '@vality/domain-proto/claim_management'; +import { getUnionKey } from '@vality/ng-thrift'; import isObject from 'lodash-es/isObject'; -import { getUnionKey } from '../../../../utils'; - import { MODIFICATIONS_NAME_TREE } from './types/modifications-name-tree'; export function getModificationName(modification: Modification) { diff --git a/src/app/sections/claims/claims-table/claims-table.component.ts b/src/app/sections/claims/claims-table/claims-table.component.ts index 0571f0ff..8c2c068a 100644 --- a/src/app/sections/claims/claims-table/claims-table.component.ts +++ b/src/app/sections/claims/claims-table/claims-table.component.ts @@ -10,10 +10,10 @@ import { import { Router } from '@angular/router'; import { Claim, ClaimStatus } from '@vality/domain-proto/claim_management'; import { Column, LoadOptions, TagColumn, createOperationColumn } from '@vality/ng-core'; +import { getUnionKey } from '@vality/ng-thrift'; import isObject from 'lodash-es/isObject'; import startCase from 'lodash-es/startCase'; -import { getUnionKey } from '../../../../utils'; import { createPartyColumn } from '../../../shared'; @Component({ diff --git a/src/app/sections/claims/claims.component.html b/src/app/sections/claims/claims.component.html index abd509bb..c009fb7f 100644 --- a/src/app/sections/claims/claims.component.html +++ b/src/app/sections/claims/claims.component.html @@ -20,7 +20,7 @@ {{ - status | keyTitle | titlecase + status | ngtKeyTitle | titlecase }} diff --git a/src/app/sections/claims/claims.module.ts b/src/app/sections/claims/claims.module.ts index 13d66b1c..3bd5511e 100644 --- a/src/app/sections/claims/claims.module.ts +++ b/src/app/sections/claims/claims.module.ts @@ -13,10 +13,10 @@ import { MatProgressBarModule } from '@angular/material/progress-bar'; import { MatSelectModule } from '@angular/material/select'; import { MatSnackBarModule } from '@angular/material/snack-bar'; import { ActionsModule, DialogModule, TableModule, FiltersModule } from '@vality/ng-core'; +import { ThriftPipesModule } from '@vality/ng-thrift'; import { PageLayoutModule } from '@cc/app/shared/components'; import { MerchantFieldModule } from '@cc/app/shared/components/merchant-field'; -import { ThriftPipesModule } from '@cc/app/shared/pipes'; import { ClaimsComponentRouting } from './claims-routing.module'; import { ClaimsTableComponent } from './claims-table/claims-table.component'; diff --git a/src/app/sections/deposit-details/deposit-details.component.ts b/src/app/sections/deposit-details/deposit-details.component.ts index ff0dc544..d023a657 100644 --- a/src/app/sections/deposit-details/deposit-details.component.ts +++ b/src/app/sections/deposit-details/deposit-details.component.ts @@ -4,17 +4,16 @@ import { ActivatedRoute } from '@angular/router'; import { DepositStatus, RevertStatus } from '@vality/fistful-proto/fistful_stat'; import { Timestamp } from '@vality/fistful-proto/internal/base'; import { formatCurrency, getImportValue } from '@vality/ng-core'; +import { getUnionKey, getUnionValue, isTypeWithAliases } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; import { of, Observable } from 'rxjs'; import { take, map } from 'rxjs/operators'; -import { getUnionKey, getUnionValue } from '../../../utils'; import { ManagementService } from '../../api/wallet'; import { MetadataViewExtension, MetadataViewExtensionResult, } from '../../shared/components/json-viewer'; -import { isTypeWithAliases } from '../../shared/components/metadata-form'; import { AmountCurrencyService } from '../../shared/services'; import { FetchSourcesService } from '../sources'; diff --git a/src/app/sections/deposit-details/reverts/create-revert-dialog/create-revert-dialog.component.ts b/src/app/sections/deposit-details/reverts/create-revert-dialog/create-revert-dialog.component.ts index bb84407d..50a136c3 100644 --- a/src/app/sections/deposit-details/reverts/create-revert-dialog/create-revert-dialog.component.ts +++ b/src/app/sections/deposit-details/reverts/create-revert-dialog/create-revert-dialog.component.ts @@ -10,16 +10,14 @@ import { FormControl } from '@angular/forms'; import { DepositParams } from '@vality/fistful-proto/deposit'; import { Revert } from '@vality/fistful-proto/internal/deposit_revert'; import { DialogSuperclass, NotifyLogService, clean } from '@vality/ng-core'; +import { isTypeWithAliases } from '@vality/ng-thrift'; import { BehaviorSubject, of } from 'rxjs'; import { Overwrite } from 'utility-types'; import { DepositManagementService } from '@cc/app/api/deposit'; import { Cash } from '../../../../../components/cash-field'; -import { - MetadataFormExtension, - isTypeWithAliases, -} from '../../../../shared/components/metadata-form'; +import { MetadataFormExtension } from '../../../../shared/components/metadata-form'; import { UserInfoBasedIdGeneratorService } from '../../../../shared/services'; import { CreateRevertDialogConfig } from './types/create-revert-dialog-config'; diff --git a/src/app/sections/deposit-details/reverts/reverts.component.ts b/src/app/sections/deposit-details/reverts/reverts.component.ts index 23fceaf9..9f31e08e 100644 --- a/src/app/sections/deposit-details/reverts/reverts.component.ts +++ b/src/app/sections/deposit-details/reverts/reverts.component.ts @@ -1,13 +1,12 @@ import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core'; import { DepositStatus, StatDeposit, StatDepositRevert } from '@vality/fistful-proto/fistful_stat'; import { DialogService, Column, UpdateOptions } from '@vality/ng-core'; +import { getUnionKey } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; import { filter } from 'rxjs/operators'; import { createCurrencyColumn } from '@cc/app/shared/utils'; -import { getUnionKey } from '../../../../utils'; - import { CreateRevertDialogComponent } from './create-revert-dialog/create-revert-dialog.component'; import { FetchRevertsService } from './services/fetch-reverts/fetch-reverts.service'; diff --git a/src/app/sections/deposit-details/services/receive-deposit/receive-deposit.service.ts b/src/app/sections/deposit-details/services/receive-deposit/receive-deposit.service.ts index 44b617da..8d0b5c65 100644 --- a/src/app/sections/deposit-details/services/receive-deposit/receive-deposit.service.ts +++ b/src/app/sections/deposit-details/services/receive-deposit/receive-deposit.service.ts @@ -1,18 +1,13 @@ import { Injectable } from '@angular/core'; -import { NotifyLogService } from '@vality/ng-core'; -import { merge, ReplaySubject, Subject, EMPTY } from 'rxjs'; +import { NotifyLogService, inProgressFrom, progressTo } from '@vality/ng-core'; +import { ReplaySubject, Subject, EMPTY, defer, BehaviorSubject } from 'rxjs'; import { catchError, switchMap, shareReplay, map } from 'rxjs/operators'; import { FistfulStatisticsService, createDsl } from '@cc/app/api/fistful-stat'; -import { progress } from '@cc/app/shared/custom-operators'; @Injectable() export class ReceiveDepositService { - private receiveDeposit$ = new ReplaySubject(); - private error$ = new Subject(); - - // eslint-disable-next-line @typescript-eslint/member-ordering - deposit$ = this.receiveDeposit$.pipe( + deposit$ = defer(() => this.receiveDeposit$).pipe( switchMap((depositId) => this.fistfulStatisticsService .GetDeposits({ dsl: createDsl({ deposits: { deposit_id: depositId, size: 1 } }) }) @@ -22,14 +17,17 @@ export class ReceiveDepositService { this.log.error(err); return EMPTY; }), - ), + ) + .pipe(progressTo(this.progress$)), ), map(({ data }) => data?.deposits[0]), shareReplay(1), ); + isLoading$ = inProgressFrom(() => this.progress$, this.deposit$); - // eslint-disable-next-line @typescript-eslint/member-ordering - isLoading$ = progress(this.receiveDeposit$, merge(this.deposit$, this.error$)); + private receiveDeposit$ = new ReplaySubject(); + private error$ = new Subject(); + private progress$ = new BehaviorSubject(0); constructor( private fistfulStatisticsService: FistfulStatisticsService, diff --git a/src/app/sections/deposits/create-deposit-dialog/create-deposit-dialog.component.ts b/src/app/sections/deposits/create-deposit-dialog/create-deposit-dialog.component.ts index 7e74f432..d5718a35 100644 --- a/src/app/sections/deposits/create-deposit-dialog/create-deposit-dialog.component.ts +++ b/src/app/sections/deposits/create-deposit-dialog/create-deposit-dialog.component.ts @@ -3,13 +3,14 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { FormControl, Validators } from '@angular/forms'; import { DepositParams } from '@vality/fistful-proto/deposit'; import { DialogSuperclass, NotifyLogService, progressTo } from '@vality/ng-core'; +import { isTypeWithAliases } from '@vality/ng-thrift'; import { BehaviorSubject, of } from 'rxjs'; import { first, map, switchMap } from 'rxjs/operators'; import { Overwrite } from 'utility-types'; import { SourceCash } from '../../../../components/source-cash-field'; import { DepositManagementService } from '../../../api/deposit'; -import { MetadataFormExtension, isTypeWithAliases } from '../../../shared/components/metadata-form'; +import { MetadataFormExtension } from '../../../shared/components/metadata-form'; import { UserInfoBasedIdGeneratorService } from '../../../shared/services'; import { FetchSourcesService } from '../../sources'; diff --git a/src/app/sections/deposits/deposits.component.ts b/src/app/sections/deposits/deposits.component.ts index 570d49b6..7cdc86cd 100644 --- a/src/app/sections/deposits/deposits.component.ts +++ b/src/app/sections/deposits/deposits.component.ts @@ -18,11 +18,11 @@ import { getValueChanges, countChanged, } from '@vality/ng-core'; +import { getUnionKey } from '@vality/ng-thrift'; import { endOfDay } from 'date-fns'; import startCase from 'lodash-es/startCase'; import { filter, map, shareReplay } from 'rxjs/operators'; -import { getUnionKey } from '../../../utils'; import { QueryDsl } from '../../api/fistful-stat'; import { createCurrencyColumn } from '../../shared'; import { DATE_RANGE_DAYS, DEBOUNCE_TIME_MS } from '../../tokens'; diff --git a/src/app/sections/domain/domain-info/domain-info.module.ts b/src/app/sections/domain/domain-info/domain-info.module.ts index e18647e0..1d0b36d8 100644 --- a/src/app/sections/domain/domain-info/domain-info.module.ts +++ b/src/app/sections/domain/domain-info/domain-info.module.ts @@ -9,8 +9,9 @@ import { MatSidenavModule } from '@angular/material/sidenav'; import { MatSnackBarModule } from '@angular/material/snack-bar'; import { RouterModule } from '@angular/router'; import { PipesModule, ActionsModule } from '@vality/ng-core'; +import { ThriftPipesModule } from '@vality/ng-thrift'; -import { ThriftPipesModule, PageLayoutModule } from '../../../shared'; +import { PageLayoutModule } from '../../../shared'; import { DomainThriftViewerComponent } from '../../../shared/components/thrift-api-crud'; import { ThriftViewerModule } from '../../../shared/components/thrift-viewer'; diff --git a/src/app/sections/domain/domain.module.ts b/src/app/sections/domain/domain.module.ts index 2a686537..90a17697 100644 --- a/src/app/sections/domain/domain.module.ts +++ b/src/app/sections/domain/domain.module.ts @@ -3,10 +3,9 @@ import { NgModule } from '@angular/core'; import { DomainInfoModule } from './domain-info'; import { DomainRoutingModule } from './domain-routing.module'; import { MetadataService } from './services/metadata.service'; -import { ModifiedDomainObjectService } from './services/modified-domain-object.service'; @NgModule({ imports: [DomainRoutingModule, DomainInfoModule], - providers: [MetadataService, ModifiedDomainObjectService], + providers: [MetadataService], }) export class DomainModule {} diff --git a/src/app/sections/domain/services/domain-obj-modification.service.ts b/src/app/sections/domain/services/domain-obj-modification.service.ts deleted file mode 100644 index 435c9cea..00000000 --- a/src/app/sections/domain/services/domain-obj-modification.service.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { Injectable } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; -import { DomainObject, Reference } from '@vality/domain-proto/domain'; -import { NotifyLogService } from '@vality/ng-core'; -import { Observable, switchMap, BehaviorSubject, defer } from 'rxjs'; -import { map, shareReplay, first } from 'rxjs/operators'; - -import { toJson, getUnionValue, progressTo } from '@cc/utils'; - -import { DomainStoreService } from '../../../api/domain-config'; - -import { MetadataService } from './metadata.service'; - -@Injectable() -export class DomainObjModificationService { - progress$ = new BehaviorSubject(0); - fullObject$ = defer(() => this.ref$).pipe(switchMap((ref) => this.getDomainObject(ref, true))); - object$ = defer(() => this.ref$).pipe( - switchMap((ref) => this.getDomainObject(ref, false).pipe(progressTo(this.progress$))), - map((obj) => getUnionValue(obj)), - shareReplay({ refCount: true, bufferSize: 1 }), - ); - type$ = defer(() => this.ref$).pipe( - switchMap((ref) => this.metadataService.getDomainObjectType(ref)), - shareReplay({ refCount: true, bufferSize: 1 }), - ); - - private ref$ = this.route.queryParams.pipe( - map(({ ref }) => { - try { - return JSON.parse(ref as string) as Reference; - } catch (err) { - this.log.error(err, 'Malformed domain object ref'); - return null; - } - }), - ); - - constructor( - private route: ActivatedRoute, - private domainStoreService: DomainStoreService, - private metadataService: MetadataService, - private log: NotifyLogService, - ) {} - - private getDomainObject(ref: Reference, rawDomain: boolean): Observable { - return this.domainStoreService.getDomain(rawDomain).pipe( - first(), - map((domain) => { - const searchRef = JSON.stringify(ref); - return domain.get( - Array.from(domain.keys()).find((k) => JSON.stringify(toJson(k)) === searchRef), - ); - }), - ); - } -} diff --git a/src/app/sections/domain/services/modified-domain-object.service.ts b/src/app/sections/domain/services/modified-domain-object.service.ts deleted file mode 100644 index 767ac03f..00000000 --- a/src/app/sections/domain/services/modified-domain-object.service.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Injectable } from '@angular/core'; -import { DomainObject } from '@vality/domain-proto/domain'; - -@Injectable() -export class ModifiedDomainObjectService { - domainObject: DomainObject; - ref: string; - - update(domainObject: DomainObject, ref: string) { - this.domainObject = domainObject; - this.ref = ref; - } -} diff --git a/src/app/sections/party/party.component.html b/src/app/sections/party/party.component.html index fd54b2a3..b4bd41be 100644 --- a/src/app/sections/party/party.component.html +++ b/src/app/sections/party/party.component.html @@ -5,15 +5,15 @@ {{ party?.blocking | ccUnionKey | titlecase }}{{ party?.blocking | ngtUnionKey | titlecase }} {{ party?.suspension | ccUnionKey | titlecase }}{{ party?.suspension | ngtUnionKey | titlecase }}
diff --git a/src/app/sections/party/party.module.ts b/src/app/sections/party/party.module.ts index d3056984..4fe890d3 100644 --- a/src/app/sections/party/party.module.ts +++ b/src/app/sections/party/party.module.ts @@ -5,8 +5,9 @@ import { MatSidenavModule } from '@angular/material/sidenav'; import { MatTabsModule } from '@angular/material/tabs'; import { MatToolbar } from '@angular/material/toolbar'; import { NavComponent, TagModule } from '@vality/ng-core'; +import { ThriftPipesModule } from '@vality/ng-thrift'; -import { PageLayoutModule, ThriftPipesModule } from '../../shared'; +import { PageLayoutModule } from '../../shared'; import { PartyRouting } from './party-routing.module'; import { PartyComponent } from './party.component'; diff --git a/src/app/sections/payment-details/payment-details.component.ts b/src/app/sections/payment-details/payment-details.component.ts index 3df4002f..0f345ef8 100644 --- a/src/app/sections/payment-details/payment-details.component.ts +++ b/src/app/sections/payment-details/payment-details.component.ts @@ -10,15 +10,14 @@ import { formatCurrency, Color, } from '@vality/ng-core'; +import { getUnionKey, getUnionValue, isTypeWithAliases } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; import { Subject, merge, defer, Observable, of } from 'rxjs'; import { shareReplay, switchMap, map } from 'rxjs/operators'; import { InvoicingService } from '@cc/app/api/payment-processing'; -import { getUnionKey, getUnionValue } from '../../../utils'; import { MetadataViewExtension } from '../../shared/components/json-viewer'; -import { isTypeWithAliases } from '../../shared/components/metadata-form'; import { DomainMetadataViewExtensionsService } from '../../shared/components/thrift-api-crud/domain/domain-thrift-viewer/services/domain-metadata-view-extensions'; import { AmountCurrencyService } from '../../shared/services'; diff --git a/src/app/sections/payment-details/payment-details.module.ts b/src/app/sections/payment-details/payment-details.module.ts index 1d45441c..92eb1a55 100644 --- a/src/app/sections/payment-details/payment-details.module.ts +++ b/src/app/sections/payment-details/payment-details.module.ts @@ -13,7 +13,7 @@ import { HeadlineModule } from '@cc/components/headline'; import { ChargebacksComponent } from '../../shared/components/chargebacks/chargebacks.component'; import { JsonViewerModule } from '../../shared/components/json-viewer'; -import { MetadataFormModule } from '../../shared/components/metadata-form'; +import { ThriftFormModule } from '../../shared/components/metadata-form'; import { MagistaThriftViewerComponent } from '../../shared/components/thrift-api-crud'; import { ThriftViewerModule } from '../../shared/components/thrift-viewer'; @@ -36,7 +36,7 @@ import { RefundsTableModule } from './refunds-table'; ChargebacksComponent, ActionsModule, DialogModule, - MetadataFormModule, + ThriftFormModule, ReactiveFormsModule, PageLayoutModule, ThriftViewerModule, diff --git a/src/app/sections/payment-details/refunds-table/refunds-table.component.ts b/src/app/sections/payment-details/refunds-table/refunds-table.component.ts index 04572ae7..a89357bf 100644 --- a/src/app/sections/payment-details/refunds-table/refunds-table.component.ts +++ b/src/app/sections/payment-details/refunds-table/refunds-table.component.ts @@ -1,9 +1,9 @@ import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core'; import { InvoicePaymentID, InvoiceID, PartyID } from '@vality/domain-proto/domain'; import { Column, UpdateOptions } from '@vality/ng-core'; +import { getUnionKey } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; -import { getUnionKey } from '../../../../utils'; import { Refund } from '../../../api/fistful-stat'; import { createCurrencyColumn } from '../../../shared'; diff --git a/src/app/sections/payment-details/refunds-table/refunds-table.module.ts b/src/app/sections/payment-details/refunds-table/refunds-table.module.ts index 4ee47c76..62f2316b 100644 --- a/src/app/sections/payment-details/refunds-table/refunds-table.module.ts +++ b/src/app/sections/payment-details/refunds-table/refunds-table.module.ts @@ -2,8 +2,9 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; import { TableModule } from '@vality/ng-core'; +import { ThriftPipesModule } from '@vality/ng-thrift'; -import { StatusModule, CommonPipesModule, ThriftPipesModule } from '../../../shared'; +import { StatusModule, CommonPipesModule } from '../../../shared'; import { RefundsTableComponent } from './refunds-table.component'; diff --git a/src/app/sections/payments/components/payments-table/payments-table.component.ts b/src/app/sections/payments/components/payments-table/payments-table.component.ts index 9d1d840d..9957258a 100644 --- a/src/app/sections/payments/components/payments-table/payments-table.component.ts +++ b/src/app/sections/payments/components/payments-table/payments-table.component.ts @@ -3,10 +3,10 @@ import { Router } from '@angular/router'; import { InvoicePaymentStatus } from '@vality/domain-proto/domain'; import { StatPayment } from '@vality/magista-proto/magista'; import { Column, TagColumn, LoadOptions, createOperationColumn } from '@vality/ng-core'; +import { getUnionKey } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; import { AmountCurrencyService } from '@cc/app/shared/services'; -import { getUnionKey } from '@cc/utils'; import { createFailureColumn, createPartyColumn, createShopColumn } from '../../../../shared'; import { createProviderColumn } from '../../../../shared/utils/table/create-provider-column'; diff --git a/src/app/sections/payments/payments.component.ts b/src/app/sections/payments/payments.component.ts index ea0aec93..504e276f 100644 --- a/src/app/sections/payments/payments.component.ts +++ b/src/app/sections/payments/payments.component.ts @@ -16,6 +16,7 @@ import { getValueChanges, countChanged, } from '@vality/ng-core'; +import { isTypeWithAliases } from '@vality/ng-thrift'; import { endOfDay } from 'date-fns'; import { uniq } from 'lodash-es'; import isEqual from 'lodash-es/isEqual'; @@ -23,7 +24,7 @@ import { BehaviorSubject, of, merge } from 'rxjs'; import { startWith, map, distinctUntilChanged, shareReplay } from 'rxjs/operators'; import { FailMachinesDialogComponent, Type } from '../../shared/components/fail-machines-dialog'; -import { MetadataFormExtension, isTypeWithAliases } from '../../shared/components/metadata-form'; +import { MetadataFormExtension } from '../../shared/components/metadata-form'; import { DATE_RANGE_DAYS, DEBOUNCE_TIME_MS } from '../../tokens'; import { CreatePaymentAdjustmentComponent } from './components/create-payment-adjustment/create-payment-adjustment.component'; diff --git a/src/app/sections/payments/payments.module.ts b/src/app/sections/payments/payments.module.ts index c181a0b9..8eb1f67f 100644 --- a/src/app/sections/payments/payments.module.ts +++ b/src/app/sections/payments/payments.module.ts @@ -13,7 +13,7 @@ import { import { PageLayoutModule, ShopFieldModule } from '@cc/app/shared'; import { MerchantFieldModule } from '@cc/app/shared/components/merchant-field'; -import { MetadataFormModule } from '@cc/app/shared/components/metadata-form'; +import { ThriftFormModule } from '@cc/app/shared/components/metadata-form'; import { MagistaThriftFormComponent } from '../../shared/components/thrift-api-crud'; @@ -34,7 +34,7 @@ import { PaymentsComponent } from './payments.component'; ReactiveFormsModule, TableModule, DialogModule, - MetadataFormModule, + ThriftFormModule, MatButtonModule, ShopFieldModule, InputFieldModule, diff --git a/src/app/sections/payouts/payout-details/payout-details.component.html b/src/app/sections/payouts/payout-details/payout-details.component.html index 0ee86890..5f198e7b 100644 --- a/src/app/sections/payouts/payout-details/payout-details.component.html +++ b/src/app/sections/payouts/payout-details/payout-details.component.html @@ -1,7 +1,7 @@ + diff --git a/src/app/shared/components/metadata-form/components/complex-form/complex-form.component.ts b/src/app/shared/components/metadata-form/components/complex-form/complex-form.component.ts index c013a3bb..3c869faa 100644 --- a/src/app/shared/components/metadata-form/components/complex-form/complex-form.component.ts +++ b/src/app/shared/components/metadata-form/components/complex-form/complex-form.component.ts @@ -8,13 +8,12 @@ import { AbstractControl, } from '@angular/forms'; import { FormComponentSuperclass, createControlProviders, getErrorsTree } from '@vality/ng-core'; +import { ThriftData } from '@vality/ng-thrift'; import { MapType, SetType, ListType } from '@vality/thrift-ts'; import { merge } from 'rxjs'; import { MetadataFormExtension } from '@cc/app/shared/components/metadata-form'; -import { MetadataFormData } from '../../types/metadata-form-data'; - function updateFormArray(formArray: FormArray>, values: V[]) { formArray.clear({ emitEvent: false }); values.forEach((v) => { @@ -35,7 +34,7 @@ export class ComplexFormComponent extends FormComponentSuperclass> implements OnInit, Validator { - @Input() data: MetadataFormData; + @Input() data: ThriftData; @Input() extensions: MetadataFormExtension[]; valueControls = new FormArray>([]); diff --git a/src/app/shared/components/metadata-form/components/enum-field/enum-field.component.ts b/src/app/shared/components/metadata-form/components/enum-field/enum-field.component.ts index 7200dea7..6e811e02 100644 --- a/src/app/shared/components/metadata-form/components/enum-field/enum-field.component.ts +++ b/src/app/shared/components/metadata-form/components/enum-field/enum-field.component.ts @@ -1,7 +1,6 @@ import { Component, Input } from '@angular/core'; import { createControlProviders, FormControlSuperclass } from '@vality/ng-core'; - -import { MetadataFormData } from '../../types/metadata-form-data'; +import { ThriftData } from '@vality/ng-thrift'; @Component({ selector: 'cc-enum-field', @@ -9,5 +8,5 @@ import { MetadataFormData } from '../../types/metadata-form-data'; providers: createControlProviders(() => EnumFieldComponent), }) export class EnumFieldComponent extends FormControlSuperclass { - @Input() data: MetadataFormData; + @Input() data: ThriftData; } diff --git a/src/app/shared/components/metadata-form/components/extension-field/extension-field.component.ts b/src/app/shared/components/metadata-form/components/extension-field/extension-field.component.ts index 24fee2c2..d92d480a 100644 --- a/src/app/shared/components/metadata-form/components/extension-field/extension-field.component.ts +++ b/src/app/shared/components/metadata-form/components/extension-field/extension-field.component.ts @@ -2,13 +2,11 @@ import { Component, Input, OnChanges, OnInit, DestroyRef } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { Validator, ValidationErrors, FormControl, Validators } from '@angular/forms'; import { FormComponentSuperclass, ComponentChanges, createControlProviders } from '@vality/ng-core'; +import { getValueTypeTitle, getAliases, ThriftData } from '@vality/ng-thrift'; import { ThriftType } from '@vality/thrift-ts'; import { defer, switchMap, ReplaySubject, Observable, combineLatest } from 'rxjs'; import { shareReplay, first, map, pluck } from 'rxjs/operators'; -import { getValueTypeTitle } from '@cc/app/shared/pipes'; - -import { getAliases, MetadataFormData } from '../../types/metadata-form-data'; import { Converter, MetadataFormExtension, @@ -25,7 +23,7 @@ export class ExtensionFieldComponent extends FormComponentSuperclass implements Validator, OnChanges, OnInit { - @Input() data: MetadataFormData; + @Input() data: ThriftData; @Input() extensions: MetadataFormExtension[]; control = new FormControl(null); @@ -47,7 +45,7 @@ export class ExtensionFieldComponent .join(', '); } - private data$ = new ReplaySubject(1); + private data$ = new ReplaySubject(1); private extensions$ = new ReplaySubject(1); private converter$: Observable = this.extensionResult$.pipe( map( diff --git a/src/app/shared/components/metadata-form/components/primitive-field/primitive-field.component.ts b/src/app/shared/components/metadata-form/components/primitive-field/primitive-field.component.ts index 7d0f2bef..94e2bfa7 100644 --- a/src/app/shared/components/metadata-form/components/primitive-field/primitive-field.component.ts +++ b/src/app/shared/components/metadata-form/components/primitive-field/primitive-field.component.ts @@ -7,6 +7,7 @@ import { createControlProviders, getValueChanges, } from '@vality/ng-core'; +import { getValueTypeTitle, ThriftData, getAliases } from '@vality/ng-thrift'; import { ThriftType } from '@vality/thrift-ts'; import { combineLatest, defer, ReplaySubject, switchMap, Observable } from 'rxjs'; import { map, shareReplay } from 'rxjs/operators'; @@ -14,11 +15,8 @@ import { map, shareReplay } from 'rxjs/operators'; import { MetadataFormExtensionResult, MetadataFormExtension, - getAliases, } from '@cc/app/shared/components/metadata-form'; -import { getValueTypeTitle } from '../../../../pipes'; -import { MetadataFormData } from '../../types/metadata-form-data'; import { getExtensionsResult } from '../../types/metadata-form-extension'; @Component({ @@ -31,7 +29,7 @@ export class PrimitiveFieldComponent extends FormControlSuperclass implements OnChanges, OnInit { - @Input() data: MetadataFormData; + @Input() data: ThriftData; @Input() extensions: MetadataFormExtension[]; extensionResult$: Observable = combineLatest([ @@ -95,7 +93,7 @@ export class PrimitiveFieldComponent } } - private data$ = new ReplaySubject>(1); + private data$ = new ReplaySubject>(1); private extensions$ = new ReplaySubject(1); constructor(private destroyRef: DestroyRef) { diff --git a/src/app/shared/components/metadata-form/components/struct-form/struct-form.component.ts b/src/app/shared/components/metadata-form/components/struct-form/struct-form.component.ts index 37884609..8954be97 100644 --- a/src/app/shared/components/metadata-form/components/struct-form/struct-form.component.ts +++ b/src/app/shared/components/metadata-form/components/struct-form/struct-form.component.ts @@ -14,12 +14,12 @@ import { getValueChanges, getErrorsTree, } from '@vality/ng-core'; +import { ThriftData, isRequiredField } from '@vality/ng-thrift'; import isNil from 'lodash-es/isNil'; import omitBy from 'lodash-es/omitBy'; import { combineLatest } from 'rxjs'; import { map, distinctUntilChanged } from 'rxjs/operators'; -import { MetadataFormData, isRequiredField } from '../../types/metadata-form-data'; import { MetadataFormExtension } from '../../types/metadata-form-extension'; @Component({ @@ -31,7 +31,7 @@ export class StructFormComponent extends FormComponentSuperclass implements OnChanges, OnInit { - @Input() data: MetadataFormData; + @Input() data: ThriftData; @Input() extensions: MetadataFormExtension[]; control: FormGroup = this.fb.group({} as T); diff --git a/src/app/shared/components/metadata-form/components/typedef-form/typedef-form.component.ts b/src/app/shared/components/metadata-form/components/typedef-form/typedef-form.component.ts index 041bf149..461f6ad9 100644 --- a/src/app/shared/components/metadata-form/components/typedef-form/typedef-form.component.ts +++ b/src/app/shared/components/metadata-form/components/typedef-form/typedef-form.component.ts @@ -1,15 +1,14 @@ import { Component, Input } from '@angular/core'; import { createControlProviders, FormControlSuperclass } from '@vality/ng-core'; +import { ThriftData } from '@vality/ng-thrift'; -import { MetadataFormData } from '../../types/metadata-form-data'; import { MetadataFormExtension } from '../../types/metadata-form-extension'; - @Component({ selector: 'cc-typedef-form', templateUrl: './typedef-form.component.html', providers: createControlProviders(() => TypedefFormComponent), }) export class TypedefFormComponent extends FormControlSuperclass { - @Input() data: MetadataFormData; + @Input() data: ThriftData; @Input() extensions: MetadataFormExtension[]; } diff --git a/src/app/shared/components/metadata-form/components/union-field/union-field.component.ts b/src/app/shared/components/metadata-form/components/union-field/union-field.component.ts index 13d92dae..e0f73752 100644 --- a/src/app/shared/components/metadata-form/components/union-field/union-field.component.ts +++ b/src/app/shared/components/metadata-form/components/union-field/union-field.component.ts @@ -7,13 +7,13 @@ import { getErrorsTree, ComponentChanges, } from '@vality/ng-core'; +import { getFieldLabel, ThriftData } from '@vality/ng-thrift'; import { Field } from '@vality/thrift-ts'; import { merge, ReplaySubject, defer } from 'rxjs'; import { delay, distinctUntilChanged, map, shareReplay } from 'rxjs/operators'; -import { MetadataFormData } from '../../types/metadata-form-data'; import { MetadataFormExtension } from '../../types/metadata-form-extension'; -import { getFieldLabel, getDefaultValue } from '../../utils'; +import { getDefaultValue } from '../../utils'; @Component({ selector: 'cc-union-field', @@ -24,7 +24,7 @@ export class UnionFieldComponent extends FormComponentSuperclass implements OnInit, Validator, OnChanges { - @Input() data: MetadataFormData; + @Input() data: ThriftData; @Input() extensions: MetadataFormExtension[]; fieldControl = new FormControl() as FormControl; @@ -39,7 +39,7 @@ export class UnionFieldComponent shareReplay({ refCount: true, bufferSize: 1 }), ); - private data$ = new ReplaySubject>(1); + private data$ = new ReplaySubject>(1); constructor(private destroyRef: DestroyRef) { super(); diff --git a/src/app/shared/components/metadata-form/index.ts b/src/app/shared/components/metadata-form/index.ts index 4fe1274b..905fc459 100644 --- a/src/app/shared/components/metadata-form/index.ts +++ b/src/app/shared/components/metadata-form/index.ts @@ -1,5 +1,4 @@ -export * from './metadata-form.module'; -export * from './types/metadata-form-data'; +export * from './thrift-form.module'; export { MetadataFormExtension } from './types/metadata-form-extension'; export { MetadataFormExtensionResult } from './types/metadata-form-extension'; export { MetadataFormExtensionOption } from './types/metadata-form-extension'; diff --git a/src/app/shared/components/metadata-form/pipes/field-label.pipe.ts b/src/app/shared/components/metadata-form/pipes/field-label.pipe.ts index 13e41215..bb02b63a 100644 --- a/src/app/shared/components/metadata-form/pipes/field-label.pipe.ts +++ b/src/app/shared/components/metadata-form/pipes/field-label.pipe.ts @@ -1,8 +1,7 @@ import { Pipe, PipeTransform } from '@angular/core'; +import { getFieldLabel } from '@vality/ng-thrift'; import { ValueType, Field } from '@vality/thrift-ts'; -import { getFieldLabel } from '../utils'; - @Pipe({ name: 'fieldLabel', }) diff --git a/src/app/shared/components/metadata-form/metadata-form.component.html b/src/app/shared/components/metadata-form/thrift-form.component.html similarity index 100% rename from src/app/shared/components/metadata-form/metadata-form.component.html rename to src/app/shared/components/metadata-form/thrift-form.component.html diff --git a/src/app/shared/components/metadata-form/metadata-form.component.scss b/src/app/shared/components/metadata-form/thrift-form.component.scss similarity index 100% rename from src/app/shared/components/metadata-form/metadata-form.component.scss rename to src/app/shared/components/metadata-form/thrift-form.component.scss diff --git a/src/app/shared/components/metadata-form/metadata-form.component.ts b/src/app/shared/components/metadata-form/thrift-form.component.ts similarity index 85% rename from src/app/shared/components/metadata-form/metadata-form.component.ts rename to src/app/shared/components/metadata-form/thrift-form.component.ts index d4b4bfd8..c70953bb 100644 --- a/src/app/shared/components/metadata-form/metadata-form.component.ts +++ b/src/app/shared/components/metadata-form/thrift-form.component.ts @@ -3,11 +3,11 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { Validator } from '@angular/forms'; import { ThriftAstMetadata } from '@vality/domain-proto'; import { createControlProviders, FormControlSuperclass } from '@vality/ng-core'; +import { ThriftData } from '@vality/ng-thrift'; import { Field, ValueType } from '@vality/thrift-ts'; import { Observable, BehaviorSubject, defer, switchMap } from 'rxjs'; import { map, distinctUntilChanged, shareReplay } from 'rxjs/operators'; -import { MetadataFormData } from './types/metadata-form-data'; import { MetadataFormExtension, MetadataFormExtensionResult, @@ -16,11 +16,11 @@ import { @Component({ selector: 'cc-metadata-form', - templateUrl: './metadata-form.component.html', - styleUrl: `./metadata-form.component.scss`, - providers: createControlProviders(() => MetadataFormComponent), + templateUrl: './thrift-form.component.html', + styleUrl: `./thrift-form.component.scss`, + providers: createControlProviders(() => ThriftFormComponent), }) -export class MetadataFormComponent +export class ThriftFormComponent extends FormControlSuperclass implements OnInit, OnChanges, Validator { @@ -28,12 +28,12 @@ export class MetadataFormComponent @Input() namespace: string; @Input() type: ValueType; @Input() field?: Field; - @Input() parent?: MetadataFormData; + @Input() parent?: ThriftData; @Input() extensions?: MetadataFormExtension[]; @HostBinding('class.cc-metadata-form-hidden') hidden = false; - data: MetadataFormData; + data: ThriftData; extensionResult$: Observable = defer(() => this.updated$).pipe( switchMap(() => getExtensionsResult(this.extensions, this.data)), shareReplay({ refCount: true, bufferSize: 1 }), @@ -61,7 +61,7 @@ export class MetadataFormComponent ngOnChanges() { if (this.metadata && this.namespace && this.type) { try { - this.data = new MetadataFormData( + this.data = new ThriftData( this.metadata, this.namespace, this.type, diff --git a/src/app/shared/components/metadata-form/metadata-form.module.ts b/src/app/shared/components/metadata-form/thrift-form.module.ts similarity index 88% rename from src/app/shared/components/metadata-form/metadata-form.module.ts rename to src/app/shared/components/metadata-form/thrift-form.module.ts index 70c11ca2..912c8bbc 100644 --- a/src/app/shared/components/metadata-form/metadata-form.module.ts +++ b/src/app/shared/components/metadata-form/thrift-form.module.ts @@ -20,10 +20,9 @@ import { AutocompleteFieldModule, TagModule, } from '@vality/ng-core'; +import { ThriftPipesModule, ValueTypeTitlePipe } from '@vality/ng-thrift'; import { JsonViewerModule } from '@cc/app/shared/components/json-viewer'; -import { ThriftPipesModule } from '@cc/app/shared/pipes/thrift'; -import { ValueTypeTitleModule } from '@cc/app/shared/pipes/value-type-title'; import { ComplexFormComponent } from './components/complex-form/complex-form.component'; import { EnumFieldComponent } from './components/enum-field/enum-field.component'; @@ -32,8 +31,8 @@ import { PrimitiveFieldComponent } from './components/primitive-field/primitive- import { StructFormComponent } from './components/struct-form/struct-form.component'; import { TypedefFormComponent } from './components/typedef-form/typedef-form.component'; import { UnionFieldComponent } from './components/union-field/union-field.component'; -import { MetadataFormComponent } from './metadata-form.component'; import { FieldLabelPipe } from './pipes/field-label.pipe'; +import { ThriftFormComponent } from './thrift-form.component'; @NgModule({ imports: [ @@ -50,7 +49,7 @@ import { FieldLabelPipe } from './pipes/field-label.pipe'; OverlayModule, MatCardModule, MatExpansionModule, - ValueTypeTitleModule, + ValueTypeTitlePipe, MatCheckboxModule, MatChipsModule, MatRadioModule, @@ -61,7 +60,7 @@ import { FieldLabelPipe } from './pipes/field-label.pipe'; TagModule, ], declarations: [ - MetadataFormComponent, + ThriftFormComponent, PrimitiveFieldComponent, ComplexFormComponent, StructFormComponent, @@ -71,6 +70,6 @@ import { FieldLabelPipe } from './pipes/field-label.pipe'; FieldLabelPipe, ExtensionFieldComponent, ], - exports: [MetadataFormComponent], + exports: [ThriftFormComponent], }) -export class MetadataFormModule {} +export class ThriftFormModule {} diff --git a/src/app/shared/components/metadata-form/types/metadata-form-data.ts b/src/app/shared/components/metadata-form/types/metadata-form-data.ts deleted file mode 100644 index fb508c79..00000000 --- a/src/app/shared/components/metadata-form/types/metadata-form-data.ts +++ /dev/null @@ -1,145 +0,0 @@ -import { ThriftAstMetadata } from '@vality/domain-proto'; -import { Field, ValueType } from '@vality/thrift-ts'; -import { JsonAST } from '@vality/thrift-ts/src/thrift-parser'; -import { ValuesType } from 'utility-types'; - -import { - isComplexType, - isPrimitiveType, - parseNamespaceObjectType, - parseNamespaceType, - StructureType, -} from '@cc/utils/thrift-instance'; - -export enum TypeGroup { - Complex = 'complex', - Primitive = 'primitive', - Object = 'object', -} - -export function getAliases(data: MetadataFormData): MetadataFormData[] { - let alias: MetadataFormData = data?.parent; - const path: MetadataFormData[] = []; - while (alias && alias.objectType === 'typedef' && alias.parent) { - path.push(alias); - alias = alias?.parent; - } - return path; -} - -export function getByType( - data: MetadataFormData, - type: string, - namespace: string, -): MetadataFormData { - return data - ? [data, ...getAliases(data)].find((d) => d.type === type && d.namespace === namespace) - : null; -} - -export function isTypeWithAliases( - data: MetadataFormData, - type: string, - namespace: string, -): boolean { - return Boolean(getByType(data, type, namespace)); -} - -export function isRequiredField(field: Field): boolean { - return field?.option === 'required'; // optional even if not explicitly stated -} - -export class MetadataFormData< - T extends ValueType = ValueType, - S extends StructureType = StructureType, -> { - typeGroup: TypeGroup; - - namespace: string; - type: T; - - objectType?: S; - ast?: ValuesType; - - include?: JsonAST['include']; - - /** - * Parent who is not typedef - */ - get trueParent() { - let data: MetadataFormData = this.parent; - while (data?.objectType === 'typedef') { - data = data.parent; - } - return data; - } - - /** - * Path to the object without aliases - */ - get trueTypeNode() { - const typedefs: MetadataFormData[] = []; - let currentData: MetadataFormData = this as never; - while (currentData.objectType === 'typedef') { - typedefs.push(currentData as never); - currentData = currentData.create({ - type: (currentData as MetadataFormData).ast.type, - }); - } - return { data: currentData, typedefs }; - } - - get isRequired() { - return isRequiredField(this.field) || this.trueParent?.objectType === 'union'; - } - - constructor( - public metadata: ThriftAstMetadata[], - namespace: string, - type: T, - public field?: Field, - public parent?: MetadataFormData, - ) { - this.setNamespaceType(namespace, type); - this.setTypeGroup(); - if (this.typeGroup === TypeGroup.Object) { - this.setNamespaceObjectType(); - } - } - - create(params: { type?: ValueType; field?: Field }): MetadataFormData { - return new MetadataFormData( - this.metadata, - this.namespace, - params.type ?? params.field?.type, - params.field, - this as never, - ); - } - - private setNamespaceType(namespace: string, type: T) { - const namespaceType = parseNamespaceType(type, namespace); - this.namespace = namespaceType.namespace; - this.type = namespaceType.type; - } - - private setTypeGroup(type: ValueType = this.type) { - this.typeGroup = isComplexType(type) - ? TypeGroup.Complex - : isPrimitiveType(this.type) - ? TypeGroup.Primitive - : TypeGroup.Object; - } - - private setNamespaceObjectType() { - const { namespaceMetadata, objectType, include } = parseNamespaceObjectType( - this.metadata, - this.namespace, - this.type as string, - this.parent?.include, - ); - this.objectType = objectType as never; - this.ast = (namespaceMetadata.ast[this.objectType] as unknown)[this.type] as never; - this.include = include; - } -} diff --git a/src/app/shared/components/metadata-form/types/metadata-form-extension.ts b/src/app/shared/components/metadata-form/types/metadata-form-extension.ts index 0f4519e1..fc19aca5 100644 --- a/src/app/shared/components/metadata-form/types/metadata-form-extension.ts +++ b/src/app/shared/components/metadata-form/types/metadata-form-extension.ts @@ -1,13 +1,12 @@ import { TemplateRef } from '@angular/core'; import { ThemePalette } from '@angular/material/core'; +import { ThriftData } from '@vality/ng-thrift'; import { Observable, combineLatest, switchMap, of } from 'rxjs'; import { map } from 'rxjs/operators'; -import { MetadataFormData } from './metadata-form-data'; - export type MetadataFormExtension = { - determinant: (data: MetadataFormData) => Observable; - extension: (data: MetadataFormData) => Observable; + determinant: (data: ThriftData) => Observable; + extension: (data: ThriftData) => Observable; }; export interface Converter { @@ -35,7 +34,7 @@ export interface MetadataFormExtensionOption { export function getExtensionsResult( sourceExtensions: MetadataFormExtension[], - data: MetadataFormData, + data: ThriftData, ): Observable { return sourceExtensions?.length ? combineLatest(sourceExtensions.map(({ determinant }) => determinant(data))).pipe( diff --git a/src/app/shared/components/metadata-form/utils/get-default-value.ts b/src/app/shared/components/metadata-form/utils/get-default-value.ts index 2119c1bb..e5287da4 100644 --- a/src/app/shared/components/metadata-form/utils/get-default-value.ts +++ b/src/app/shared/components/metadata-form/utils/get-default-value.ts @@ -1,16 +1,15 @@ import { ThriftAstMetadata } from '@vality/domain-proto'; +import { ThriftData, TypeGroup } from '@vality/ng-thrift'; import { ValueType } from '@vality/thrift-ts'; import { TypeDefs } from '@vality/thrift-ts/src/thrift-parser'; -import { MetadataFormData, TypeGroup } from '../types/metadata-form-data'; - export function getDefaultValue(metadata: ThriftAstMetadata[], namespace: string, type: ValueType) { if (!type) { return null; } - let data: MetadataFormData; + let data: ThriftData; do { - data = new MetadataFormData(metadata, namespace, type); + data = new ThriftData(metadata, namespace, type); type = (data.ast as TypeDefs[string])?.type; } while (data.objectType === 'typedef'); switch (data.typeGroup) { diff --git a/src/app/shared/components/metadata-form/utils/get-field-label.ts b/src/app/shared/components/metadata-form/utils/get-field-label.ts deleted file mode 100644 index 056819c7..00000000 --- a/src/app/shared/components/metadata-form/utils/get-field-label.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Field, ValueType } from '@vality/thrift-ts'; -import startCase from 'lodash-es/startCase'; - -import { getValueTypeTitle } from '../../../pipes'; - -export function getFieldLabel(type: ValueType, field?: Field) { - return type ? startCase((field ? field.name : getValueTypeTitle(type)).toLowerCase()) : ''; -} diff --git a/src/app/shared/components/metadata-form/utils/index.ts b/src/app/shared/components/metadata-form/utils/index.ts index 8eab1e9e..f54da47b 100644 --- a/src/app/shared/components/metadata-form/utils/index.ts +++ b/src/app/shared/components/metadata-form/utils/index.ts @@ -1,2 +1 @@ -export * from './get-field-label'; export * from './get-default-value'; diff --git a/src/app/shared/components/page-layout/page-layout.module.ts b/src/app/shared/components/page-layout/page-layout.module.ts index 0fcf276f..185401f1 100644 --- a/src/app/shared/components/page-layout/page-layout.module.ts +++ b/src/app/shared/components/page-layout/page-layout.module.ts @@ -7,8 +7,7 @@ import { MatToolbar } from '@angular/material/toolbar'; import { MatTooltipModule } from '@angular/material/tooltip'; import { RouterLink } from '@angular/router'; import { ActionsModule, TagModule } from '@vality/ng-core'; - -import { ThriftPipesModule } from '../../pipes'; +import { ThriftPipesModule } from '@vality/ng-thrift'; import { PageLayoutActionsComponent } from './components/page-layout-actions/page-layout-actions.component'; import { PageLayoutComponent } from './page-layout.component'; diff --git a/src/app/shared/components/payout-tool-details/payout-tool-details.component.html b/src/app/shared/components/payout-tool-details/payout-tool-details.component.html index b6c0e351..9ecac4b8 100644 --- a/src/app/shared/components/payout-tool-details/payout-tool-details.component.html +++ b/src/app/shared/components/payout-tool-details/payout-tool-details.component.html @@ -6,7 +6,7 @@

International bank account

- +

Russian bank account

- +

Wallet

{{ payoutTool.payout_tool_info.wallet_info.wallet_id @@ -41,7 +41,7 @@

Payment institution account

diff --git a/src/app/shared/components/payout-tool-details/payout-tool-details.module.ts b/src/app/shared/components/payout-tool-details/payout-tool-details.module.ts index 9e064cad..2a33d9a6 100644 --- a/src/app/shared/components/payout-tool-details/payout-tool-details.module.ts +++ b/src/app/shared/components/payout-tool-details/payout-tool-details.module.ts @@ -1,7 +1,7 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; +import { ThriftPipesModule } from '@vality/ng-thrift'; -import { ThriftPipesModule } from '@cc/app/shared/pipes'; import { DetailsItemModule } from '@cc/components/details-item'; import { InternationalBankAccountDetailsComponent } from './components/international-bank-account-details/international-bank-account-details.component'; diff --git a/src/app/shared/components/shops-table/shops-table.component.ts b/src/app/shared/components/shops-table/shops-table.component.ts index 616ca911..a89a19ec 100644 --- a/src/app/shared/components/shops-table/shops-table.component.ts +++ b/src/app/shared/components/shops-table/shops-table.component.ts @@ -15,12 +15,12 @@ import { DialogResponseStatus, ComponentChanges, } from '@vality/ng-core'; +import { getUnionKey } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; import { map, switchMap, Subject, defer, combineLatest } from 'rxjs'; import { filter, shareReplay, startWith, take, first } from 'rxjs/operators'; import { MemoizeExpiring } from 'typescript-memoize'; -import { getUnionKey } from '../../../../utils'; import { DomainStoreService } from '../../../api/domain-config'; import { PartyManagementService } from '../../../api/payment-processing'; import { PartyDelegateRulesetsService } from '../../../sections/routing-rules/party-delegate-rulesets'; diff --git a/src/app/shared/components/status/pipes/to-status/to-status.pipe.ts b/src/app/shared/components/status/pipes/to-status/to-status.pipe.ts index 53f6184f..f503536d 100644 --- a/src/app/shared/components/status/pipes/to-status/to-status.pipe.ts +++ b/src/app/shared/components/status/pipes/to-status/to-status.pipe.ts @@ -1,8 +1,7 @@ import { Pipe, PipeTransform } from '@angular/core'; +import { getUnionKey } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; -import { getUnionKey } from '@cc/utils/get-union-key'; - @Pipe({ name: 'toStatus', }) diff --git a/src/app/shared/components/terminal-delegates-card/terminal-delegates-card.component.ts b/src/app/shared/components/terminal-delegates-card/terminal-delegates-card.component.ts index 245ce46d..e5e39c4c 100644 --- a/src/app/shared/components/terminal-delegates-card/terminal-delegates-card.component.ts +++ b/src/app/shared/components/terminal-delegates-card/terminal-delegates-card.component.ts @@ -2,11 +2,11 @@ import { CommonModule } from '@angular/common'; import { Component, Input, OnChanges } from '@angular/core'; import { TerminalRef } from '@vality/domain-proto/domain'; import { ComponentChanges, TableModule, Column } from '@vality/ng-core'; +import { getUnionKey, getUnionValue } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; import { ReplaySubject, defer, switchMap } from 'rxjs'; import { map, shareReplay } from 'rxjs/operators'; -import { getUnionKey, getUnionValue } from '../../../../utils'; import { DomainStoreService } from '../../../api/domain-config'; import { PartiesStoreService } from '../../../api/payment-processing'; import { diff --git a/src/app/shared/components/thrift-api-crud/domain/create-domain-object-dialog/create-domain-object-dialog.component.ts b/src/app/shared/components/thrift-api-crud/domain/create-domain-object-dialog/create-domain-object-dialog.component.ts index ff501c29..18889cca 100644 --- a/src/app/shared/components/thrift-api-crud/domain/create-domain-object-dialog/create-domain-object-dialog.component.ts +++ b/src/app/shared/components/thrift-api-crud/domain/create-domain-object-dialog/create-domain-object-dialog.component.ts @@ -13,11 +13,11 @@ import { progressTo, NotifyLogService, } from '@vality/ng-core'; +import { getUnionKey } from '@vality/ng-thrift'; import { BehaviorSubject, switchMap, EMPTY } from 'rxjs'; import { first, map, catchError } from 'rxjs/operators'; import { ValuesType } from 'utility-types'; -import { getUnionKey } from '../../../../../../utils'; import { DomainStoreService } from '../../../../../api/domain-config'; import { DomainNavigateService } from '../../../../../sections/domain/services/domain-navigate.service'; import { MetadataService } from '../../../../../sections/domain/services/metadata.service'; diff --git a/src/app/shared/components/thrift-api-crud/domain/domain-object-card/domain-object-card.component.ts b/src/app/shared/components/thrift-api-crud/domain/domain-object-card/domain-object-card.component.ts index bff2d5d9..4e7a3adb 100644 --- a/src/app/shared/components/thrift-api-crud/domain/domain-object-card/domain-object-card.component.ts +++ b/src/app/shared/components/thrift-api-crud/domain/domain-object-card/domain-object-card.component.ts @@ -5,11 +5,11 @@ import { MatButtonModule } from '@angular/material/button'; import { Router } from '@angular/router'; import { Reference } from '@vality/domain-proto/internal/domain'; import { ComponentChanges, DialogService } from '@vality/ng-core'; +import { isEqualThrift } from '@vality/ng-thrift'; import { combineLatest, ReplaySubject, switchMap } from 'rxjs'; import { map, shareReplay, first } from 'rxjs/operators'; import { DomainStoreService } from '@cc/app/api/domain-config'; -import { isEqualThrift } from '@cc/utils'; import { SidenavInfoModule } from '../../../sidenav-info'; import { CardComponent } from '../../../sidenav-info/components/card/card.component'; diff --git a/src/app/shared/components/thrift-api-crud/domain/domain-thrift-form/domain-thrift-form.component.ts b/src/app/shared/components/thrift-api-crud/domain/domain-thrift-form/domain-thrift-form.component.ts index a164965f..273b9e39 100644 --- a/src/app/shared/components/thrift-api-crud/domain/domain-thrift-form/domain-thrift-form.component.ts +++ b/src/app/shared/components/thrift-api-crud/domain/domain-thrift-form/domain-thrift-form.component.ts @@ -10,7 +10,7 @@ import { combineLatest, filter } from 'rxjs'; import { shareReplay, startWith, map } from 'rxjs/operators'; import { DomainMetadataFormExtensionsService } from '../../../../services'; -import { MetadataFormModule } from '../../../metadata-form'; +import { ThriftFormModule } from '../../../metadata-form'; import { ThriftEditorModule } from '../../../thrift-editor'; import { BaseThriftFormSuperclass } from '../../thrift-forms/utils/thrift-form-superclass'; @@ -19,7 +19,7 @@ import { BaseThriftFormSuperclass } from '../../thrift-forms/utils/thrift-form-s selector: 'cc-domain-thrift-form', templateUrl: './domain-thrift-form.component.html', providers: createControlProviders(() => DomainThriftFormComponent), - imports: [CommonModule, ReactiveFormsModule, MetadataFormModule, ThriftEditorModule], + imports: [CommonModule, ReactiveFormsModule, ThriftFormModule, ThriftEditorModule], }) export class DomainThriftFormComponent extends BaseThriftFormSuperclass { party = input(); diff --git a/src/app/shared/components/thrift-api-crud/domain/domain-thrift-viewer/services/domain-metadata-view-extensions/domain-metadata-view-extensions.service.ts b/src/app/shared/components/thrift-api-crud/domain/domain-thrift-viewer/services/domain-metadata-view-extensions/domain-metadata-view-extensions.service.ts index 9d999a66..115680b1 100644 --- a/src/app/shared/components/thrift-api-crud/domain/domain-thrift-viewer/services/domain-metadata-view-extensions/domain-metadata-view-extensions.service.ts +++ b/src/app/shared/components/thrift-api-crud/domain/domain-thrift-viewer/services/domain-metadata-view-extensions/domain-metadata-view-extensions.service.ts @@ -6,6 +6,7 @@ import { DomainObject } from '@vality/domain-proto/domain'; import { Rational, Timestamp } from '@vality/domain-proto/internal/base'; import { PartyID, ShopID } from '@vality/domain-proto/internal/domain'; import { getImportValue } from '@vality/ng-core'; +import { getUnionValue, isTypeWithAliases, ThriftData } from '@vality/ng-thrift'; import isEqual from 'lodash-es/isEqual'; import round from 'lodash-es/round'; import { of, Observable } from 'rxjs'; @@ -13,9 +14,7 @@ import { map, shareReplay } from 'rxjs/operators'; import { DomainStoreService } from '@cc/app/api/domain-config'; import { MetadataViewExtension } from '@cc/app/shared/components/json-viewer'; -import { isTypeWithAliases, MetadataFormData } from '@cc/app/shared/components/metadata-form'; -import { getUnionValue } from '../../../../../../../../utils'; import { PartiesStoreService } from '../../../../../../../api/payment-processing'; import { SidenavInfoService } from '../../../../../sidenav-info'; import { getDomainObjectDetails } from '../../../utils'; @@ -94,14 +93,11 @@ export class DomainMetadataViewExtensionsService { } createDomainObjectExtensions(metadata: ThriftAstMetadata[]): MetadataViewExtension[] { - const domainFields = new MetadataFormData( - metadata, - 'domain', - 'DomainObject', - ).ast; + const domainFields = new ThriftData(metadata, 'domain', 'DomainObject') + .ast; return domainFields.map((f) => { const objectKey = f.name as keyof DomainObject; - const objectFields = new MetadataFormData( + const objectFields = new ThriftData( metadata, 'domain', f.type as string, diff --git a/src/app/shared/components/thrift-api-crud/domain/edit-domain-object-dialog/edit-domain-object-dialog.component.ts b/src/app/shared/components/thrift-api-crud/domain/edit-domain-object-dialog/edit-domain-object-dialog.component.ts index 0e187c46..c0ad8a1a 100644 --- a/src/app/shared/components/thrift-api-crud/domain/edit-domain-object-dialog/edit-domain-object-dialog.component.ts +++ b/src/app/shared/components/thrift-api-crud/domain/edit-domain-object-dialog/edit-domain-object-dialog.component.ts @@ -15,15 +15,14 @@ import { progressTo, inProgressFrom, } from '@vality/ng-core'; +import { isEqualThrift, getUnionKey, getUnionValue, ThriftPipesModule } from '@vality/ng-thrift'; import { BehaviorSubject, switchMap, EMPTY, combineLatest, Observable } from 'rxjs'; import { first, map, shareReplay, catchError, distinctUntilChanged } from 'rxjs/operators'; import { ValuesType } from 'utility-types'; -import { getUnionKey, getUnionValue, isEqualThrift } from '../../../../../../utils'; import { DomainStoreService } from '../../../../../api/domain-config'; import { DomainNavigateService } from '../../../../../sections/domain/services/domain-navigate.service'; import { MetadataService } from '../../../../../sections/domain/services/metadata.service'; -import { ThriftPipesModule } from '../../../../pipes'; import { DomainSecretService } from '../../../../services'; import { DomainThriftFormComponent } from '../domain-thrift-form'; import { DomainThriftViewerComponent } from '../domain-thrift-viewer'; diff --git a/src/app/shared/components/thrift-api-crud/domain/utils/get-domain-object-details.ts b/src/app/shared/components/thrift-api-crud/domain/utils/get-domain-object-details.ts index f05bb39e..b8c2dc02 100644 --- a/src/app/shared/components/thrift-api-crud/domain/utils/get-domain-object-details.ts +++ b/src/app/shared/components/thrift-api-crud/domain/utils/get-domain-object-details.ts @@ -1,10 +1,9 @@ import { DomainObject } from '@vality/domain-proto/domain'; import { inlineJson } from '@vality/ng-core'; +import { getUnionKey, getUnionValue } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; import { PickByValue, ValuesType } from 'utility-types'; -import { getUnionKey, getUnionValue } from '../../../../../../utils'; - export interface DomainObjectDetails { id: number | string; label: string; diff --git a/src/app/shared/components/thrift-api-crud/magista/magista-thrift-form/magista-thrift-form.component.ts b/src/app/shared/components/thrift-api-crud/magista/magista-thrift-form/magista-thrift-form.component.ts index aa7d7b87..f7f7d68d 100644 --- a/src/app/shared/components/thrift-api-crud/magista/magista-thrift-form/magista-thrift-form.component.ts +++ b/src/app/shared/components/thrift-api-crud/magista/magista-thrift-form/magista-thrift-form.component.ts @@ -4,7 +4,7 @@ import { ReactiveFormsModule } from '@angular/forms'; import { ThriftAstMetadata } from '@vality/fistful-proto'; import { createControlProviders, getImportValue } from '@vality/ng-core'; -import { MetadataFormModule } from '../../../metadata-form'; +import { ThriftFormModule } from '../../../metadata-form'; import { ThriftEditorModule } from '../../../thrift-editor'; import { BaseThriftFormSuperclass } from '../../thrift-forms/utils/thrift-form-superclass'; @@ -13,7 +13,7 @@ import { BaseThriftFormSuperclass } from '../../thrift-forms/utils/thrift-form-s selector: 'cc-magista-thrift-form', templateUrl: './magista-thrift-form.component.html', providers: createControlProviders(() => MagistaThriftFormComponent), - imports: [CommonModule, ReactiveFormsModule, MetadataFormModule, ThriftEditorModule], + imports: [CommonModule, ReactiveFormsModule, ThriftFormModule, ThriftEditorModule], }) export class MagistaThriftFormComponent extends BaseThriftFormSuperclass { metadata$ = getImportValue(import('@vality/magista-proto/metadata.json')); diff --git a/src/app/shared/components/thrift-editor/thrift-editor.component.ts b/src/app/shared/components/thrift-editor/thrift-editor.component.ts index eaebbea5..d40fe897 100644 --- a/src/app/shared/components/thrift-editor/thrift-editor.component.ts +++ b/src/app/shared/components/thrift-editor/thrift-editor.component.ts @@ -8,11 +8,10 @@ import { createControlProviders, FormControlSuperclass, } from '@vality/ng-core'; +import { toJson } from '@vality/ng-thrift'; import { merge, defer, of, Subject } from 'rxjs'; import { map, filter, shareReplay } from 'rxjs/operators'; -import { objectToJSON } from '@cc/utils/thrift-instance'; - import { MetadataFormExtension } from '../metadata-form'; export enum EditorKind { @@ -102,6 +101,6 @@ export class ThriftEditorComponent extends FormControlSuperclass { } private createMonacoContent(value: unknown): string { - return JSON.stringify(objectToJSON(value), null, 2); + return JSON.stringify(toJson(value), null, 2); } } diff --git a/src/app/shared/components/thrift-editor/thrift-editor.module.ts b/src/app/shared/components/thrift-editor/thrift-editor.module.ts index 25aa26b3..d02575b0 100644 --- a/src/app/shared/components/thrift-editor/thrift-editor.module.ts +++ b/src/app/shared/components/thrift-editor/thrift-editor.module.ts @@ -8,7 +8,7 @@ import { MatTooltipModule } from '@angular/material/tooltip'; import { PipesModule } from '@vality/ng-core'; import { MonacoEditorModule } from 'ngx-monaco-editor-v2'; -import { MetadataFormModule } from '@cc/app/shared/components/metadata-form'; +import { ThriftFormModule } from '@cc/app/shared/components/metadata-form'; import { ThriftEditorComponent } from './thrift-editor.component'; @@ -17,7 +17,7 @@ import { ThriftEditorComponent } from './thrift-editor.component'; exports: [ThriftEditorComponent], imports: [ CommonModule, - MetadataFormModule, + ThriftFormModule, ReactiveFormsModule, MonacoEditorModule, MatButtonToggleModule, diff --git a/src/app/shared/components/thrift-viewer/thrift-viewer.component.ts b/src/app/shared/components/thrift-viewer/thrift-viewer.component.ts index 7b2227f6..c47df368 100644 --- a/src/app/shared/components/thrift-viewer/thrift-viewer.component.ts +++ b/src/app/shared/components/thrift-viewer/thrift-viewer.component.ts @@ -1,12 +1,12 @@ import { Component, Input, OnChanges, Output, EventEmitter, booleanAttribute } from '@angular/core'; import { ThriftAstMetadata } from '@vality/domain-proto'; import { ComponentChanges } from '@vality/ng-core'; +import { toJson } from '@vality/ng-thrift'; import { ValueType } from '@vality/thrift-ts'; import { DiffEditorModel } from 'ngx-monaco-editor-v2'; import { ReplaySubject } from 'rxjs'; import { MetadataViewExtension } from '@cc/app/shared/components/json-viewer'; -import { objectToJSON } from '@cc/utils/thrift-instance'; export enum ViewerKind { Editor = 'editor', @@ -41,13 +41,13 @@ export class ThriftViewerComponent implements OnChanges { ngOnChanges(changes: ComponentChanges>) { if (changes.value) { this.valueFile$.next({ - code: JSON.stringify(objectToJSON(this.value), null, 2), + code: JSON.stringify(toJson(this.value), null, 2), language: 'json', }); } if (changes.compared) { this.comparedFile$.next({ - code: JSON.stringify(objectToJSON(this.compared), null, 2), + code: JSON.stringify(toJson(this.compared), null, 2), language: 'json', }); } diff --git a/src/app/shared/components/thrift-viewer/thrift-viewer.module.ts b/src/app/shared/components/thrift-viewer/thrift-viewer.module.ts index 9749f817..c88673a3 100644 --- a/src/app/shared/components/thrift-viewer/thrift-viewer.module.ts +++ b/src/app/shared/components/thrift-viewer/thrift-viewer.module.ts @@ -7,7 +7,7 @@ import { MatIconModule } from '@angular/material/icon'; import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; import { MonacoEditorModule } from 'ngx-monaco-editor-v2'; -import { MetadataFormModule } from '@cc/app/shared/components/metadata-form'; +import { ThriftFormModule } from '@cc/app/shared/components/metadata-form'; import { JsonViewerModule } from '../json-viewer'; @@ -18,7 +18,7 @@ import { ThriftViewerComponent } from './thrift-viewer.component'; exports: [ThriftViewerComponent], imports: [ CommonModule, - MetadataFormModule, + ThriftFormModule, ReactiveFormsModule, MonacoEditorModule, MatButtonToggleModule, diff --git a/src/app/shared/custom-operators/index.ts b/src/app/shared/custom-operators/index.ts deleted file mode 100644 index 2ee57814..00000000 --- a/src/app/shared/custom-operators/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './progress'; diff --git a/src/app/shared/custom-operators/progress.ts b/src/app/shared/custom-operators/progress.ts deleted file mode 100644 index c3e0b251..00000000 --- a/src/app/shared/custom-operators/progress.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { merge, Observable, of } from 'rxjs'; -import { catchError, distinctUntilChanged, map, startWith } from 'rxjs/operators'; - -export const progress = ( - start$: Observable, - end$: Observable, - startValue = false, -): Observable => - merge(start$.pipe(map(() => true)), end$.pipe(map(() => false))).pipe( - catchError(() => of(false)), - startWith(startValue), - distinctUntilChanged(), - ); diff --git a/src/app/shared/pipes/index.ts b/src/app/shared/pipes/index.ts index c9353f5a..d0b93236 100644 --- a/src/app/shared/pipes/index.ts +++ b/src/app/shared/pipes/index.ts @@ -1,3 +1 @@ -export * from './thrift'; export * from './common'; -export * from './value-type-title'; diff --git a/src/app/shared/pipes/thrift/index.ts b/src/app/shared/pipes/thrift/index.ts deleted file mode 100644 index 313685d3..00000000 --- a/src/app/shared/pipes/thrift/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './thrift-pipes.module'; diff --git a/src/app/shared/pipes/thrift/key-title.pipe.ts b/src/app/shared/pipes/thrift/key-title.pipe.ts deleted file mode 100644 index 6a7ca5aa..00000000 --- a/src/app/shared/pipes/thrift/key-title.pipe.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Pipe, PipeTransform } from '@angular/core'; - -@Pipe({ - name: 'keyTitle', -}) -export class KeyTitlePipe implements PipeTransform { - transform(value: unknown): string { - return String(value).replaceAll('_', ' '); - } -} diff --git a/src/app/shared/pipes/thrift/map-union.pipe.ts b/src/app/shared/pipes/thrift/map-union.pipe.ts deleted file mode 100644 index da9d0e26..00000000 --- a/src/app/shared/pipes/thrift/map-union.pipe.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Pipe, PipeTransform } from '@angular/core'; - -import { getUnionKey } from '@cc/utils/get-union-key'; - -@Pipe({ - name: 'ccMapUnion', -}) -export class MapUnionPipe implements PipeTransform { - public transform(union: T, mapObject: { [N in keyof T]: string | number }) { - return mapObject[getUnionKey(union)]; - } -} diff --git a/src/app/shared/pipes/thrift/thrift-int64.pipe.ts b/src/app/shared/pipes/thrift/thrift-int64.pipe.ts deleted file mode 100644 index 35779445..00000000 --- a/src/app/shared/pipes/thrift/thrift-int64.pipe.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Pipe, PipeTransform } from '@angular/core'; -import { Int64 } from '@vality/thrift-ts'; - -@Pipe({ - name: 'ccThriftInt64', -}) -/** - * @deprecated - */ -export class ThriftInt64Pipe implements PipeTransform { - transform(value: Int64 | number): number { - return typeof value === 'number' ? value : value.toNumber(); - } -} diff --git a/src/app/shared/pipes/thrift/thrift-pipes.module.ts b/src/app/shared/pipes/thrift/thrift-pipes.module.ts deleted file mode 100644 index cfc101be..00000000 --- a/src/app/shared/pipes/thrift/thrift-pipes.module.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { NgModule } from '@angular/core'; - -import { KeyTitlePipe } from './key-title.pipe'; -import { MapUnionPipe } from './map-union.pipe'; -import { ThriftInt64Pipe } from './thrift-int64.pipe'; -import { UnionKeyPipe } from './union-key.pipe'; -import { UnionValuePipe } from './union-value.pipe'; - -const PIPES = [MapUnionPipe, ThriftInt64Pipe, UnionKeyPipe, KeyTitlePipe, UnionValuePipe]; - -@NgModule({ - declarations: PIPES, - exports: PIPES, -}) -export class ThriftPipesModule {} diff --git a/src/app/shared/pipes/thrift/union-key.pipe.ts b/src/app/shared/pipes/thrift/union-key.pipe.ts deleted file mode 100644 index 28d49360..00000000 --- a/src/app/shared/pipes/thrift/union-key.pipe.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Pipe, PipeTransform } from '@angular/core'; - -import { getUnionKey } from '@cc/utils/get-union-key'; - -@Pipe({ - name: 'ccUnionKey', -}) -export class UnionKeyPipe implements PipeTransform { - public transform(union: T) { - return getUnionKey(union); - } -} diff --git a/src/app/shared/pipes/thrift/union-value.pipe.ts b/src/app/shared/pipes/thrift/union-value.pipe.ts deleted file mode 100644 index dbea2b35..00000000 --- a/src/app/shared/pipes/thrift/union-value.pipe.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Pipe, PipeTransform } from '@angular/core'; - -import { getUnionValue } from '@cc/utils/get-union-key'; - -@Pipe({ - name: 'ccUnionValue', -}) -export class UnionValuePipe implements PipeTransform { - public transform(union: T) { - return getUnionValue(union); - } -} diff --git a/src/app/shared/pipes/value-type-title/index.ts b/src/app/shared/pipes/value-type-title/index.ts deleted file mode 100644 index 0d0ba4f5..00000000 --- a/src/app/shared/pipes/value-type-title/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './value-type-title.module'; -export * from './utils/get-value-type-title'; diff --git a/src/app/shared/pipes/value-type-title/utils/get-value-type-title.ts b/src/app/shared/pipes/value-type-title/utils/get-value-type-title.ts deleted file mode 100644 index 4356cb55..00000000 --- a/src/app/shared/pipes/value-type-title/utils/get-value-type-title.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { ValueType } from '@vality/thrift-ts'; - -import { isComplexType } from '@cc/utils/thrift-instance'; - -export function typeCase(str: string): string { - return str.replace(/([a-z])([A-Z])/g, '$1 $2'); -} - -export function getValueTypeTitle(valueType: ValueType): string { - if (isComplexType(valueType)) { - if (valueType.name === 'map') { - return `${valueType.name}: ${getValueTypeTitle( - valueType.keyType, - )} - ${getValueTypeTitle(valueType.valueType)}`; - } - return `${valueType.name}: ${getValueTypeTitle(valueType.valueType)}`; - } - return typeCase(valueType); -} diff --git a/src/app/shared/pipes/value-type-title/value-type-title.module.ts b/src/app/shared/pipes/value-type-title/value-type-title.module.ts deleted file mode 100644 index afdb9eb7..00000000 --- a/src/app/shared/pipes/value-type-title/value-type-title.module.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { CommonModule } from '@angular/common'; -import { NgModule } from '@angular/core'; - -import { ValueTypeTitlePipe } from './value-type-title.pipe'; - -@NgModule({ - declarations: [ValueTypeTitlePipe], - imports: [CommonModule], - exports: [ValueTypeTitlePipe], -}) -export class ValueTypeTitleModule {} diff --git a/src/app/shared/pipes/value-type-title/value-type-title.pipe.ts b/src/app/shared/pipes/value-type-title/value-type-title.pipe.ts deleted file mode 100644 index 93d425e7..00000000 --- a/src/app/shared/pipes/value-type-title/value-type-title.pipe.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Pipe, PipeTransform } from '@angular/core'; -import { ValueType } from '@vality/thrift-ts'; - -import { getValueTypeTitle } from './utils/get-value-type-title'; - -@Pipe({ - name: 'valueTypeTitle', -}) -export class ValueTypeTitlePipe implements PipeTransform { - transform(valueType: ValueType): string { - return getValueTypeTitle(valueType); - } -} diff --git a/src/app/shared/services/domain-metadata-form-extensions/domain-metadata-form-extensions.service.ts b/src/app/shared/services/domain-metadata-form-extensions/domain-metadata-form-extensions.service.ts index 5c30215f..70150bf9 100644 --- a/src/app/shared/services/domain-metadata-form-extensions/domain-metadata-form-extensions.service.ts +++ b/src/app/shared/services/domain-metadata-form-extensions/domain-metadata-form-extensions.service.ts @@ -3,6 +3,7 @@ import { ThriftAstMetadata } from '@vality/domain-proto'; import { Claim } from '@vality/domain-proto/claim_management'; import { DomainObject, Party } from '@vality/domain-proto/domain'; import { getNoTimeZoneIsoString, getImportValue } from '@vality/ng-core'; +import { ThriftData, isTypeWithAliases } from '@vality/ng-thrift'; import { Observable, of } from 'rxjs'; import { map, shareReplay } from 'rxjs/operators'; import * as short from 'short-uuid'; @@ -10,11 +11,7 @@ import * as short from 'short-uuid'; import { DomainStoreService } from '@cc/app/api/domain-config'; import { FistfulStatisticsService, createDsl } from '../../../api/fistful-stat'; -import { - MetadataFormData, - MetadataFormExtension, - isTypeWithAliases, -} from '../../components/metadata-form'; +import { MetadataFormExtension } from '../../components/metadata-form'; import { createDomainObjectExtension } from './utils/create-domain-object-extension'; import { createPartyClaimDomainMetadataFormExtensions } from './utils/create-party-claim-domain-metadata-form-extensions'; @@ -110,11 +107,8 @@ export class DomainMetadataFormExtensionsService { } private createDomainObjectsOptions(metadata: ThriftAstMetadata[]): MetadataFormExtension[] { - const domainFields = new MetadataFormData( - metadata, - 'domain', - 'DomainObject', - ).ast; + const domainFields = new ThriftData(metadata, 'domain', 'DomainObject') + .ast; return domainFields.map((f) => this.createFieldOptions(metadata, f.type as string, f.name as keyof DomainObject), ); @@ -125,8 +119,7 @@ export class DomainMetadataFormExtensionsService { objectType: string, objectKey: keyof DomainObject, ): MetadataFormExtension { - const objectFields = new MetadataFormData(metadata, 'domain', objectType) - .ast; + const objectFields = new ThriftData(metadata, 'domain', objectType).ast; const refType = objectFields.find((n) => n.name === 'ref').type as string; return createDomainObjectExtension(refType, () => this.domainStoreService.getObjects(objectKey).pipe( diff --git a/src/app/shared/services/domain-metadata-form-extensions/utils/create-domain-object-extension.ts b/src/app/shared/services/domain-metadata-form-extensions/utils/create-domain-object-extension.ts index ffed6877..45f858e8 100644 --- a/src/app/shared/services/domain-metadata-form-extensions/utils/create-domain-object-extension.ts +++ b/src/app/shared/services/domain-metadata-form-extensions/utils/create-domain-object-extension.ts @@ -1,10 +1,10 @@ +import { isTypeWithAliases } from '@vality/ng-thrift'; import { Observable, of } from 'rxjs'; import { map } from 'rxjs/operators'; import { createNextId } from '@cc/utils/create-next-id'; import { - isTypeWithAliases, MetadataFormExtension, MetadataFormExtensionOption, } from '../../../components/metadata-form'; diff --git a/src/app/shared/services/domain-metadata-form-extensions/utils/create-party-claim-domain-metadata-form-extensions.ts b/src/app/shared/services/domain-metadata-form-extensions/utils/create-party-claim-domain-metadata-form-extensions.ts index fb429060..cb0e0004 100644 --- a/src/app/shared/services/domain-metadata-form-extensions/utils/create-party-claim-domain-metadata-form-extensions.ts +++ b/src/app/shared/services/domain-metadata-form-extensions/utils/create-party-claim-domain-metadata-form-extensions.ts @@ -1,11 +1,11 @@ import { Claim, PayoutToolModificationUnit } from '@vality/domain-proto/claim_management'; import { Party } from '@vality/domain-proto/domain'; +import { isTypeWithAliases } from '@vality/ng-thrift'; import uniqBy from 'lodash-es/uniqBy'; import { of } from 'rxjs'; import * as short from 'short-uuid'; import { - isTypeWithAliases, MetadataFormExtension, MetadataFormExtensionOption, } from '../../../components/metadata-form'; diff --git a/src/app/shared/services/domain-metadata-form-extensions/utils/get-domain-object-option.ts b/src/app/shared/services/domain-metadata-form-extensions/utils/get-domain-object-option.ts index c6e14751..0dff1f95 100644 --- a/src/app/shared/services/domain-metadata-form-extensions/utils/get-domain-object-option.ts +++ b/src/app/shared/services/domain-metadata-form-extensions/utils/get-domain-object-option.ts @@ -1,7 +1,7 @@ import { DomainObject } from '@vality/domain-proto/domain'; +import { getUnionKey, getUnionValue } from '@vality/ng-thrift'; import { ValuesType } from 'utility-types'; -import { getUnionKey, getUnionValue } from '../../../../../utils'; import { MetadataFormExtensionOption } from '../../../components/metadata-form'; import { getDomainObjectValueDetailsFn } from '../../../components/thrift-api-crud'; diff --git a/src/app/shared/utils/table/format-predicate.ts b/src/app/shared/utils/table/format-predicate.ts index de523932..436b76d6 100644 --- a/src/app/shared/utils/table/format-predicate.ts +++ b/src/app/shared/utils/table/format-predicate.ts @@ -1,8 +1,7 @@ import { Predicate } from '@vality/domain-proto/domain'; +import { getUnionKey, getUnionValue } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; -import { getUnionKey, getUnionValue } from '../../../../utils'; - export function formatPredicate(predicate: Predicate, level = 0) { if (!predicate) { return ''; diff --git a/src/utils/get-union-key.ts b/src/utils/get-union-key.ts deleted file mode 100644 index 9576c4ef..00000000 --- a/src/utils/get-union-key.ts +++ /dev/null @@ -1,22 +0,0 @@ -import get from 'lodash-es/get'; -import isNil from 'lodash-es/isNil'; -import isObject from 'lodash-es/isObject'; -import { ValuesType } from 'utility-types'; - -export function getUnionKeys(obj: T): (keyof T)[] { - return obj ? (Object.keys(obj) as (keyof T)[]) : []; -} - -export function getUnionKeyValue(obj: T): { [K in keyof T]: [K, T[K]] }[keyof T] | null { - return isObject(obj) - ? (Object.entries(obj).find(([, v]) => !isNil(v)) as { [K in keyof T]: [K, T[K]] }[keyof T]) - : null; -} - -export function getUnionKey(obj: T): keyof T | null { - return get(getUnionKeyValue(obj), 0, null); -} - -export function getUnionValue(obj: T): ValuesType | null { - return get(getUnionKeyValue(obj), 1, null); -} diff --git a/src/utils/index.ts b/src/utils/index.ts index 7b6ca788..7c7103f1 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,10 +1,3 @@ -export * from './get-union-key'; -export * from './wrap-values-to-array'; -export * from './thrift-json-converter'; -export * from './thrift-utils'; export * from './has-active-fragments'; -export * from './poll'; export * from './enumerate'; -export * from './thrift-instance'; export * from './csv'; -export * from './thrift'; diff --git a/src/utils/poll.ts b/src/utils/poll.ts deleted file mode 100644 index bdb8cd6e..00000000 --- a/src/utils/poll.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { merge, Observable, timer } from 'rxjs'; -import { delay, filter, repeatWhen, takeLast, takeUntil, tap } from 'rxjs/operators'; - -const POLLING_INTERVAL = 3000; -const POLLING_TIMEOUT = 30000; - -export class PollingTimeoutError extends Error { - constructor(props) { - super(props); - Object.setPrototypeOf(this, PollingTimeoutError.prototype); - } -} - -export const poll = - (conditionFn: (value) => boolean) => - (source: Observable): Observable => { - let condition = false; - return source.pipe( - tap((value) => (condition = conditionFn(value))), - repeatWhen((notifications) => - notifications.pipe( - delay(POLLING_INTERVAL), - takeUntil( - merge( - notifications.pipe(filter(() => condition)), - timer(POLLING_TIMEOUT).pipe( - tap(() => { - throw new PollingTimeoutError('Polling timeout'); - }), - ), - ), - ), - ), - ), - takeLast(1), - ); - }; diff --git a/src/utils/thrift-instance/index.ts b/src/utils/thrift-instance/index.ts deleted file mode 100644 index ed38b909..00000000 --- a/src/utils/thrift-instance/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './namespace-type'; -export * from './object-to-json'; diff --git a/src/utils/thrift-instance/namespace-type.ts b/src/utils/thrift-instance/namespace-type.ts deleted file mode 100644 index 70560bb6..00000000 --- a/src/utils/thrift-instance/namespace-type.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { ThriftAstMetadata } from '@vality/domain-proto'; -import { JsonAST } from '@vality/thrift-ts'; - -import type { ListType, MapType, SetType, ThriftType, ValueType } from '@vality/thrift-ts'; - -export const PRIMITIVE_TYPES = [ - 'int', - 'bool', - 'i8', - 'i16', - 'i32', - 'i64', - 'string', - 'double', - 'binary', -] as const; - -export function isThriftObject(value: unknown): boolean { - return typeof value?.['write'] === 'function' && typeof value?.['read'] === 'function'; -} - -export function isComplexType(type: ValueType): type is SetType | ListType | MapType { - return typeof type === 'object'; -} - -export function isPrimitiveType(type: ValueType): type is ThriftType { - return PRIMITIVE_TYPES.includes(type as never); -} - -export type StructureType = keyof JsonAST; -export const STRUCTURE_TYPES: StructureType[] = ['typedef', 'struct', 'union', 'exception', 'enum']; - -export interface NamespaceObjectType { - namespaceMetadata: ThriftAstMetadata; - objectType: StructureType; - include: JsonAST['include']; -} - -export function parseNamespaceObjectType( - metadata: ThriftAstMetadata[], - namespace: string, - type: string, - include?: JsonAST['include'], -): NamespaceObjectType { - // metadata reverse find - search for the last matching protocol if the names match (files are overwritten in the same order) - let namespaceMetadata: ThriftAstMetadata; - if (include) { - namespaceMetadata = metadata.reverse().find((m) => m.path === include[namespace].path); - } - if (!namespaceMetadata) { - namespaceMetadata = metadata.reverse().find((m) => m.name === namespace); - } - const objectType = Object.keys(namespaceMetadata.ast).find( - (t) => namespaceMetadata.ast[t][type], - ) as StructureType; - if (!objectType || !STRUCTURE_TYPES.includes(objectType)) { - throw new Error(`Unknown thrift structure type: ${objectType}`); - } - return { - namespaceMetadata, - objectType, - include: { - ...namespaceMetadata.ast.include, - ...{ [namespace]: { path: namespaceMetadata.path } }, - }, - }; -} - -export interface NamespaceType { - namespace: string; - type: T; -} - -export function parseNamespaceType( - type: T, - namespace?: string, -): NamespaceType { - if (type && !isPrimitiveType(type) && !isComplexType(type) && type.includes('.')) { - [namespace, type as unknown] = type.split('.'); - } - return { namespace, type }; -} diff --git a/src/utils/thrift-instance/object-to-json.ts b/src/utils/thrift-instance/object-to-json.ts deleted file mode 100644 index 7b09bd9f..00000000 --- a/src/utils/thrift-instance/object-to-json.ts +++ /dev/null @@ -1,12 +0,0 @@ -export function objectToJSON(obj: unknown): unknown { - if (typeof obj !== 'object' || obj === null) { - return obj; - } else if (Array.isArray(obj)) { - return obj.map((v) => objectToJSON(v)); - } else if (obj instanceof Map) { - return Array.from(obj).map(([k, v]) => [objectToJSON(k), objectToJSON(v)]); - } else if (obj instanceof Set) { - return Array.from(obj).map((v) => objectToJSON(v)); - } - return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, objectToJSON(v)])); -} diff --git a/src/utils/thrift-json-converter.ts b/src/utils/thrift-json-converter.ts deleted file mode 100644 index 5500e584..00000000 --- a/src/utils/thrift-json-converter.ts +++ /dev/null @@ -1,61 +0,0 @@ -import has from 'lodash-es/has'; -import isObject from 'lodash-es/isObject'; - -import type { Int64 } from '@vality/thrift-ts'; - -import { clearNullFields } from './thrift-utils'; - -function resolveArray(arr: unknown[]): unknown[] { - let result = []; - for (const item of arr) { - result = result.concat(toJson(item)); - } - return result; -} - -function resolveObject(obj: unknown): unknown { - const sanitized = clearNullFields(obj); - const entries = Object.entries(sanitized); - let result = {}; - for (const [key, val] of entries) { - result = { - ...result, - [key]: isObject(val) ? toJson(val) : val, - }; - } - return result; -} - -function resolveMap(map: Map): unknown { - let result = []; - map.forEach((v, k) => { - result = result.concat({ - key: toJson(k), - value: toJson(v), - }); - }); - return result; -} - -function isI64(obj: unknown): obj is Int64 { - return has(obj, 'buffer') && has(obj, 'offset'); -} - -export function toJson(thrift: unknown): unknown { - if (!thrift) { - return; - } - if (Array.isArray(thrift)) { - return resolveArray(thrift); - } - if (thrift instanceof Map) { - return resolveMap(thrift); - } - if (isI64(thrift)) { - return thrift.toNumber(); - } - if (isObject(thrift)) { - return resolveObject(thrift); - } - return thrift; -} diff --git a/src/utils/thrift-utils.ts b/src/utils/thrift-utils.ts deleted file mode 100644 index 1100f66c..00000000 --- a/src/utils/thrift-utils.ts +++ /dev/null @@ -1,14 +0,0 @@ -export function clearNullFields(union: unknown): unknown { - if (!union) { - return; - } - const filtered = Object.entries(union).filter(([, v]) => v !== null); - let result = {}; - for (const [key, val] of filtered) { - result = { - ...result, - [key]: val, - }; - } - return result; -} diff --git a/src/utils/thrift/create-union.ts b/src/utils/thrift/create-union.ts deleted file mode 100644 index bd137d9a..00000000 --- a/src/utils/thrift/create-union.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Creates a union {[key]: {}} - * Compatible with array methods (.map and others) - */ -export function createUnion( - key: T, - value: V = {} as V, -): Record> { - return { [key]: typeof value === 'object' ? value : {} } as never; -} diff --git a/src/utils/thrift/index.ts b/src/utils/thrift/index.ts deleted file mode 100644 index 1adece7b..00000000 --- a/src/utils/thrift/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './create-union'; -export * from './is-equal-thrift'; diff --git a/src/utils/thrift/is-equal-thrift.ts b/src/utils/thrift/is-equal-thrift.ts deleted file mode 100644 index 96de4434..00000000 --- a/src/utils/thrift/is-equal-thrift.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { toJson } from '../thrift-json-converter'; - -export function isEqualThrift(a: unknown, b: unknown) { - return JSON.stringify(toJson(a)) === JSON.stringify(toJson(b)); -} diff --git a/src/utils/wrap-values-to-array.ts b/src/utils/wrap-values-to-array.ts deleted file mode 100644 index 04801bf6..00000000 --- a/src/utils/wrap-values-to-array.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const wrapValuesToArray = (params: Record): Record => - Object.entries(params).reduce((acc, [k, v]) => ({ ...acc, [k]: [v] }), {});