From 4fcc1cbde039a2764cfc48795560ab5a8820d8b2 Mon Sep 17 00:00:00 2001 From: Rinat Arsaev <11846445+KrickRay@users.noreply.github.com> Date: Thu, 24 Mar 2022 21:12:04 +0300 Subject: [PATCH] TD-237: New @vality/dominant-cache-proto API codegen (#53) --- .github/actions/init/action.yaml | 15 +--- .github/workflows/build-push.yaml | 31 ------- .github/workflows/main.yaml | 18 ++++ .github/workflows/pr-build-check.yaml | 20 ----- .github/workflows/pr.yaml | 15 ++-- package-lock.json | 23 +++-- package.json | 6 +- .../dominant-cache/dominant-cache.service.ts | 23 +++++ ...ominant-cache-instance-provider.service.ts | 17 ---- .../dominant-cache/dominant-cache.service.ts | 87 ------------------- .../dominant-cache/dominant-cache/index.ts | 1 - src/app/api/dominant-cache/index.ts | 2 +- .../deposit/deposit-management.service.ts | 2 +- .../wallet/wallet-management.service.ts | 2 +- .../magista/merchant-statistics.service.ts | 2 +- .../party-management.service.ts | 2 +- .../payout-management.service.ts | 2 +- .../thrift-instance-provider.service.ts | 2 +- .../thrift-meta-loader.service.ts | 2 +- .../types/api-metadata.ts | 2 +- .../types/provider-settings.ts | 2 +- .../create-thrift-api/create-thrift-api.ts | 12 +++ src/app/api/utils/create-thrift-api/index.ts | 1 + .../api/utils/create-thrift-api/thrift-api.ts | 59 +++++++++++++ .../types/thrift-api-args.ts | 5 ++ .../types/thrift-api-options.ts | 12 +++ src/app/api/utils/index.ts | 3 + .../api/{ => utils}/thrift-connector/index.ts | 0 .../thrift-connector/thrift-connector.ts | 0 .../utils/connect-to-thrift-service.ts | 0 .../thrift-connector/utils/index.ts | 0 .../utils/prepare-thrift-service-method.ts | 0 .../utils/to-connect-options.ts | 0 .../thrift-connector/utils/types.ts | 0 .../create-thrift-instance-utils.ts | 0 .../thrift-instance/create-thrift-instance.ts | 0 .../utils/thrift-instance/index.ts | 0 .../utils/thrift-instance/namespace-type.ts | 0 .../utils/thrift-instance/object-to-json.ts | 0 .../thrift-instance-to-object.ts | 0 .../thrift-instance/to-list-value-type.ts | 0 .../utils/thrift-instance/types/index.ts | 0 .../types/thrift-ast-metadata.ts | 0 .../types/thrift-namespace-context.ts | 0 .../shop-payment-routing-ruleset.component.ts | 4 +- .../components/category/category.component.ts | 2 +- .../contract-template-ref.component.ts | 4 +- .../category-ref/category-ref.component.ts | 4 +- .../damsel/utils/create-damsel-instance.ts | 3 +- src/app/thrift-services/index.ts | 1 - thrift-config.json | 10 --- 51 files changed, 178 insertions(+), 218 deletions(-) delete mode 100644 .github/workflows/build-push.yaml create mode 100644 .github/workflows/main.yaml delete mode 100644 .github/workflows/pr-build-check.yaml create mode 100644 src/app/api/dominant-cache/dominant-cache.service.ts delete mode 100644 src/app/api/dominant-cache/dominant-cache/dominant-cache-instance-provider.service.ts delete mode 100644 src/app/api/dominant-cache/dominant-cache/dominant-cache.service.ts delete mode 100644 src/app/api/dominant-cache/dominant-cache/index.ts create mode 100644 src/app/api/utils/create-thrift-api/create-thrift-api.ts create mode 100644 src/app/api/utils/create-thrift-api/index.ts create mode 100644 src/app/api/utils/create-thrift-api/thrift-api.ts create mode 100644 src/app/api/utils/create-thrift-api/types/thrift-api-args.ts create mode 100644 src/app/api/utils/create-thrift-api/types/thrift-api-options.ts create mode 100644 src/app/api/utils/index.ts rename src/app/api/{ => utils}/thrift-connector/index.ts (100%) rename src/app/api/{ => utils}/thrift-connector/thrift-connector.ts (100%) rename src/app/api/{ => utils}/thrift-connector/utils/connect-to-thrift-service.ts (100%) rename src/app/api/{ => utils}/thrift-connector/utils/index.ts (100%) rename src/app/api/{ => utils}/thrift-connector/utils/prepare-thrift-service-method.ts (100%) rename src/app/api/{ => utils}/thrift-connector/utils/to-connect-options.ts (100%) rename src/app/api/{ => utils}/thrift-connector/utils/types.ts (100%) rename src/app/{thrift-services => api}/utils/thrift-instance/create-thrift-instance-utils.ts (100%) rename src/app/{thrift-services => api}/utils/thrift-instance/create-thrift-instance.ts (100%) rename src/app/{thrift-services => api}/utils/thrift-instance/index.ts (100%) rename src/app/{thrift-services => api}/utils/thrift-instance/namespace-type.ts (100%) rename src/app/{thrift-services => api}/utils/thrift-instance/object-to-json.ts (100%) rename src/app/{thrift-services => api}/utils/thrift-instance/thrift-instance-to-object.ts (100%) rename src/app/{thrift-services => api}/utils/thrift-instance/to-list-value-type.ts (100%) rename src/app/{thrift-services => api}/utils/thrift-instance/types/index.ts (100%) rename src/app/{thrift-services => api}/utils/thrift-instance/types/thrift-ast-metadata.ts (100%) rename src/app/{thrift-services => api}/utils/thrift-instance/types/thrift-namespace-context.ts (100%) diff --git a/.github/actions/init/action.yaml b/.github/actions/init/action.yaml index c11f002c..2fbeb3d5 100644 --- a/.github/actions/init/action.yaml +++ b/.github/actions/init/action.yaml @@ -3,19 +3,10 @@ description: Init runs: using: composite steps: - - name: Init Thrift - uses: valitydev/action-setup-thrift@v0.0.1 - - - name: Init NodeJS - uses: actions/setup-node@v2 - with: - node-version: '16.13.2' - cache: 'npm' - - - name: Install Packages - run: npm ci + - uses: valitydev/action-frontend/setup@v0.1 + - uses: valitydev/action-setup-thrift@v1.0.0 + - run: npm ci shell: bash - - name: Compile Thrift run: npm run compile shell: bash diff --git a/.github/workflows/build-push.yaml b/.github/workflows/build-push.yaml deleted file mode 100644 index 8a08d4fa..00000000 --- a/.github/workflows/build-push.yaml +++ /dev/null @@ -1,31 +0,0 @@ -name: Build & Push -on: - push: - branches: - - 'master' - - 'main' -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Init - uses: ./.github/actions/init - - - name: Check & Build - run: npm run ci:build - - - name: Deploy image - uses: valitydev/action-deploy-docker@v1.0.16 - with: - registry-username: ${{ github.actor }} - registry-access-token: ${{ secrets.GITHUB_TOKEN }} - dockerfile-path: . - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 00000000..ff4fe1d6 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,18 @@ +name: Main +on: + push: + branches: ['master', 'main'] +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/init + - name: Build + run: npm run build + - name: Deploy image + uses: valitydev/action-deploy-docker@v2 + with: + registry-username: ${{ github.actor }} + registry-access-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pr-build-check.yaml b/.github/workflows/pr-build-check.yaml deleted file mode 100644 index f0431d23..00000000 --- a/.github/workflows/pr-build-check.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: 'PR: Build & Check' -on: - pull_request: - branches: ['*'] -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Init - uses: ./.github/actions/init - - - name: Check & Build - run: npm run ci:build diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index b4b005a6..d0a9ffb8 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -1,12 +1,13 @@ -name: 'PR Title Checker' +name: PR on: pull_request: - types: [edited, opened, synchronize, reopened] - branches: [disabled] + branches: ['*'] jobs: - title-check: + check: + name: Check runs-on: ubuntu-latest steps: - - uses: naveenk1223/action-pr-title@master - with: - regex: '([A-Z]+-[0-9]+,?)+: [A-Z0-9].*' + - uses: actions/checkout@v3 + - uses: ./.github/actions/init + - name: Check & Build + run: npm run ci:build diff --git a/package-lock.json b/package-lock.json index 0a1d9565..88112e26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "@s-libs/micro-dash": "^13.1.0", "@s-libs/ng-core": "^13.1.0", "@s-libs/rxjs-core": "^13.1.0", + "@vality/dominant-cache-proto": "1.0.1-5b29d81.0", "@vality/magista-proto": "1.0.1-f1a4bc0.0", "@vality/payout-manager-proto": "^1.0.1-cc9875f.0", "@vality/thrift-ts": "2.2.0-alpha", @@ -75,7 +76,6 @@ "damsel": "github:valitydev/damsel#318a7a6588c4813bd7d5c170af58fa9b6a80e401", "deanonimus-proto": "github:valitydev/deanonimus-proto#b9fab4fd1c7690186efdc5974d113c82bd5765e9", "del": "^5.1.0", - "dominant-cache-proto": "github:valitydev/dominant-cache-proto#ebd35c3096cb5e3222aa29317277b59a01c41fbe", "eslint": "^8.5.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "^2.22.1", @@ -5268,6 +5268,11 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@vality/dominant-cache-proto": { + "version": "1.0.1-5b29d81.0", + "resolved": "https://registry.npmjs.org/@vality/dominant-cache-proto/-/dominant-cache-proto-1.0.1-5b29d81.0.tgz", + "integrity": "sha512-mk7H5/WeaXoHPSvube14pQEzYbCxnfrdaaA0DVgAHRxQ8CvX/KEtWT4lG78H/Xrg/6WQhP79T/BvujueO5pq8w==" + }, "node_modules/@vality/magista-proto": { "version": "1.0.1-f1a4bc0.0", "resolved": "https://registry.npmjs.org/@vality/magista-proto/-/magista-proto-1.0.1-f1a4bc0.0.tgz", @@ -10126,12 +10131,6 @@ "url": "https://github.com/fb55/domhandler?sponsor=1" } }, - "node_modules/dominant-cache-proto": { - "version": "1.0.0", - "resolved": "git+ssh://git@github.com/valitydev/dominant-cache-proto.git#ebd35c3096cb5e3222aa29317277b59a01c41fbe", - "dev": true, - "license": "UNLICENSED" - }, "node_modules/domino": { "version": "2.1.6", "resolved": "https://registry.npmjs.org/domino/-/domino-2.1.6.tgz", @@ -26554,6 +26553,11 @@ } } }, + "@vality/dominant-cache-proto": { + "version": "1.0.1-5b29d81.0", + "resolved": "https://registry.npmjs.org/@vality/dominant-cache-proto/-/dominant-cache-proto-1.0.1-5b29d81.0.tgz", + "integrity": "sha512-mk7H5/WeaXoHPSvube14pQEzYbCxnfrdaaA0DVgAHRxQ8CvX/KEtWT4lG78H/Xrg/6WQhP79T/BvujueO5pq8w==" + }, "@vality/magista-proto": { "version": "1.0.1-f1a4bc0.0", "resolved": "https://registry.npmjs.org/@vality/magista-proto/-/magista-proto-1.0.1-f1a4bc0.0.tgz", @@ -30544,11 +30548,6 @@ "domelementtype": "^2.2.0" } }, - "dominant-cache-proto": { - "version": "git+ssh://git@github.com/valitydev/dominant-cache-proto.git#ebd35c3096cb5e3222aa29317277b59a01c41fbe", - "dev": true, - "from": "dominant-cache-proto@github:valitydev/dominant-cache-proto#ebd35c3096cb5e3222aa29317277b59a01c41fbe" - }, "domino": { "version": "2.1.6", "resolved": "https://registry.npmjs.org/domino/-/domino-2.1.6.tgz", diff --git a/package.json b/package.json index a6628e1d..54b1f7f6 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start": "ng serve --proxy-config proxy.conf.js --port 4200", "build": "ng build --extra-webpack-config webpack.extra.js", "test": "ng test", - "lint-cmd": "eslint \"src/**/*.{ts,js,html}\" --max-warnings 1307", + "lint-cmd": "eslint \"src/**/*.{ts,js,html}\" --max-warnings 1328", "lint-cache-cmd": "npm run lint-cmd -- --cache", "lint": "npm run lint-cache-cmd", "lint-fix": "npm run lint-cache-cmd -- --fix", @@ -42,6 +42,7 @@ "@s-libs/micro-dash": "^13.1.0", "@s-libs/ng-core": "^13.1.0", "@s-libs/rxjs-core": "^13.1.0", + "@vality/dominant-cache-proto": "1.0.1-5b29d81.0", "@vality/magista-proto": "1.0.1-f1a4bc0.0", "@vality/payout-manager-proto": "^1.0.1-cc9875f.0", "@vality/thrift-ts": "2.2.0-alpha", @@ -89,7 +90,6 @@ "damsel": "github:valitydev/damsel#318a7a6588c4813bd7d5c170af58fa9b6a80e401", "deanonimus-proto": "github:valitydev/deanonimus-proto#b9fab4fd1c7690186efdc5974d113c82bd5765e9", "del": "^5.1.0", - "dominant-cache-proto": "github:valitydev/dominant-cache-proto#ebd35c3096cb5e3222aa29317277b59a01c41fbe", "eslint": "^8.5.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "^2.22.1", @@ -117,4 +117,4 @@ "ts-node": "~8.8.2", "typescript": "~4.5.4" } -} \ No newline at end of file +} diff --git a/src/app/api/dominant-cache/dominant-cache.service.ts b/src/app/api/dominant-cache/dominant-cache.service.ts new file mode 100644 index 00000000..71f94e25 --- /dev/null +++ b/src/app/api/dominant-cache/dominant-cache.service.ts @@ -0,0 +1,23 @@ +import { Injectable, Injector } from '@angular/core'; +import { + codegenClientConfig, + CodegenClient, +} from '@vality/dominant-cache-proto/lib/dominant_cache-DominantCache'; +import context from '@vality/dominant-cache-proto/lib/dominant_cache/context'; +import * as DominantCache from '@vality/dominant-cache-proto/lib/dominant_cache/gen-nodejs/DominantCache'; + +import { createThriftApi } from '@cc/app/api/utils'; + +@Injectable({ providedIn: 'root' }) +export class DominantCacheService extends createThriftApi() { + constructor(injector: Injector) { + super(injector, { + service: DominantCache, + endpoint: '/v1/dominant/cache', + metadata: () => + import('@vality/dominant-cache-proto/lib/metadata.json').then((m) => m.default), + context, + ...codegenClientConfig, + }); + } +} diff --git a/src/app/api/dominant-cache/dominant-cache/dominant-cache-instance-provider.service.ts b/src/app/api/dominant-cache/dominant-cache/dominant-cache-instance-provider.service.ts deleted file mode 100644 index 19fb4009..00000000 --- a/src/app/api/dominant-cache/dominant-cache/dominant-cache-instance-provider.service.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Injectable } from '@angular/core'; - -import { ProviderSettings, ThriftInstanceProvider } from '../../thrift-instance-provider'; -import * as dominant_cache from './gen-nodejs/dominant_cache_types'; - -@Injectable({ providedIn: 'root' }) -export class DominantCacheInstanceProvider extends ThriftInstanceProvider { - protected getProviderSettings(): ProviderSettings { - return { - context: { - dominant_cache, - }, - metadataName: 'dominant-cache', - defaultNamespace: 'dominant_cache', - }; - } -} diff --git a/src/app/api/dominant-cache/dominant-cache/dominant-cache.service.ts b/src/app/api/dominant-cache/dominant-cache/dominant-cache.service.ts deleted file mode 100644 index b67dbafa..00000000 --- a/src/app/api/dominant-cache/dominant-cache/dominant-cache.service.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; -import { map, switchMap } from 'rxjs/operators'; - -import { KeycloakTokenInfoService } from '@cc/app/shared/services'; - -import { toListValueType } from '../../../thrift-services'; -import { ThriftConnector } from '../../thrift-connector'; -import { - CashRegisterProvider, - Category, - ContractTemplate, - Country, - TradeBloc, -} from '../gen-model/dominant_cache'; -import { DominantCacheInstanceProvider } from './dominant-cache-instance-provider.service'; -import * as DominantCache from './gen-nodejs/DominantCache'; - -@Injectable({ providedIn: 'root' }) -export class DominantCacheService extends ThriftConnector { - constructor( - protected keycloakTokenInfoService: KeycloakTokenInfoService, - private instanceProvider: DominantCacheInstanceProvider - ) { - super(keycloakTokenInfoService, DominantCache, '/v1/dominant/cache'); - } - - getCategories(): Observable { - return this.instanceProvider.methods$.pipe( - switchMap(({ toPlainObject }) => - this.callThriftServiceMethod('GetCategories').pipe( - map((v) => toPlainObject(toListValueType('Category'), v)) - ) - ) - ); - } - - getDocumentTypes(): Observable { - return this.instanceProvider.methods$.pipe( - switchMap(({ toPlainObject }) => - this.callThriftServiceMethod('GetDocumentTypes').pipe( - map((v) => toPlainObject(toListValueType('DocumentType'), v)) - ) - ) - ); - } - - getCashRegisterProviders(): Observable { - return this.instanceProvider.methods$.pipe( - switchMap(({ toPlainObject }) => - this.callThriftServiceMethod( - 'GetCashRegisterProviders' - ).pipe(map((v) => toPlainObject(toListValueType('CashRegisterProvider'), v))) - ) - ); - } - - getContractTemplates(): Observable { - return this.instanceProvider.methods$.pipe( - switchMap(({ toPlainObject }) => - this.callThriftServiceMethod('GetContractTemplates').pipe( - map((v) => toPlainObject(toListValueType('ContractTemplate'), v)) - ) - ) - ); - } - - getTradeBlocs(): Observable { - return this.instanceProvider.methods$.pipe( - switchMap(({ toPlainObject }) => - this.callThriftServiceMethod('GetTradeBlocs').pipe( - map((v) => toPlainObject(toListValueType('TradeBloc'), v)) - ) - ) - ); - } - - getCountries(): Observable { - return this.instanceProvider.methods$.pipe( - switchMap(({ toPlainObject }) => - this.callThriftServiceMethod('GetCountries').pipe( - map((v) => toPlainObject(toListValueType('Country'), v)) - ) - ) - ); - } -} diff --git a/src/app/api/dominant-cache/dominant-cache/index.ts b/src/app/api/dominant-cache/dominant-cache/index.ts deleted file mode 100644 index 5d8a9fbf..00000000 --- a/src/app/api/dominant-cache/dominant-cache/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './dominant-cache.service'; diff --git a/src/app/api/dominant-cache/index.ts b/src/app/api/dominant-cache/index.ts index 541087c1..5d8a9fbf 100644 --- a/src/app/api/dominant-cache/index.ts +++ b/src/app/api/dominant-cache/index.ts @@ -1 +1 @@ -export * from './dominant-cache'; +export * from './dominant-cache.service'; diff --git a/src/app/api/fistful/deposit/deposit-management.service.ts b/src/app/api/fistful/deposit/deposit-management.service.ts index 104974d5..36849248 100644 --- a/src/app/api/fistful/deposit/deposit-management.service.ts +++ b/src/app/api/fistful/deposit/deposit-management.service.ts @@ -4,7 +4,7 @@ import { map, switchMap } from 'rxjs/operators'; import { KeycloakTokenInfoService } from '@cc/app/shared/services'; -import { ThriftConnector } from '../../thrift-connector'; +import { ThriftConnector } from '../../utils/thrift-connector'; import { RevertParams, RevertState } from '../gen-model/deposit_revert'; import { DepositInstanceProvider } from './deposit-instance-provider.service'; import * as Management from './gen-nodejs/Management'; diff --git a/src/app/api/fistful/wallet/wallet-management.service.ts b/src/app/api/fistful/wallet/wallet-management.service.ts index 5f29bbd1..a7efbf79 100644 --- a/src/app/api/fistful/wallet/wallet-management.service.ts +++ b/src/app/api/fistful/wallet/wallet-management.service.ts @@ -4,7 +4,7 @@ import { map, switchMap } from 'rxjs/operators'; import { KeycloakTokenInfoService } from '@cc/app/shared/services'; -import { ThriftConnector } from '../../thrift-connector'; +import { ThriftConnector } from '../../utils/thrift-connector'; import { WalletState, EventRange } from '../gen-model/wallet'; import * as Management from './gen-nodejs/Management'; import { WalletInstanceProvider } from './wallet-instance-provider.service'; diff --git a/src/app/api/magista/merchant-statistics.service.ts b/src/app/api/magista/merchant-statistics.service.ts index bbde7c39..bdb11a34 100644 --- a/src/app/api/magista/merchant-statistics.service.ts +++ b/src/app/api/magista/merchant-statistics.service.ts @@ -4,7 +4,7 @@ import * as ThriftMerchantStatisticsService from '@vality/magista-proto/lib/magi import { Observable } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; -import { ThriftConnector } from '@cc/app/api/thrift-connector'; +import { ThriftConnector } from '@cc/app/api/utils/thrift-connector'; import { KeycloakTokenInfoService } from '@cc/app/shared/services'; import { MagistaInstanceProviderService } from './magista-instance-provider.service'; diff --git a/src/app/api/payment-processing/party-management.service.ts b/src/app/api/payment-processing/party-management.service.ts index 42bd77b0..9e2e8453 100644 --- a/src/app/api/payment-processing/party-management.service.ts +++ b/src/app/api/payment-processing/party-management.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { forkJoin, Observable } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; -import { ThriftConnector } from '@cc/app/api/thrift-connector'; +import { ThriftConnector } from '@cc/app/api/utils/thrift-connector'; import { KeycloakTokenInfoService } from '@cc/app/shared/services'; import { diff --git a/src/app/api/payout-manager/payout-management.service.ts b/src/app/api/payout-manager/payout-management.service.ts index 90126a49..88f40fec 100644 --- a/src/app/api/payout-manager/payout-management.service.ts +++ b/src/app/api/payout-manager/payout-management.service.ts @@ -4,7 +4,7 @@ import { Payout, PayoutID, PayoutParams } from '@vality/payout-manager-proto'; import { Observable } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; -import { ThriftConnector } from '@cc/app/api/thrift-connector'; +import { ThriftConnector } from '@cc/app/api/utils/thrift-connector'; import { KeycloakTokenInfoService } from '@cc/app/shared/services'; import { PayoutManagerInstanceProviderService } from './payout-manager-instance-provider.service'; diff --git a/src/app/api/thrift-instance-provider/thrift-instance-provider.service.ts b/src/app/api/thrift-instance-provider/thrift-instance-provider.service.ts index 1d1d1e83..89eac07f 100644 --- a/src/app/api/thrift-instance-provider/thrift-instance-provider.service.ts +++ b/src/app/api/thrift-instance-provider/thrift-instance-provider.service.ts @@ -3,7 +3,7 @@ import partial from 'lodash-es/partial'; import { Observable } from 'rxjs'; import { first, map } from 'rxjs/operators'; -import { createThriftInstance, thriftInstanceToObject } from '../../thrift-services'; +import { createThriftInstance, thriftInstanceToObject } from '../utils/thrift-instance'; import { ThriftMetaLoader } from './thrift-meta-loader.service'; import { ProviderMethods, ProviderSettings } from './types'; diff --git a/src/app/api/thrift-instance-provider/thrift-meta-loader.service.ts b/src/app/api/thrift-instance-provider/thrift-meta-loader.service.ts index 3c1d3637..cacb6b38 100644 --- a/src/app/api/thrift-instance-provider/thrift-meta-loader.service.ts +++ b/src/app/api/thrift-instance-provider/thrift-meta-loader.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'; import { from, Observable, ObservableInput } from 'rxjs'; import { shareReplay } from 'rxjs/operators'; -import { ThriftAstMetadata } from '../../thrift-services'; +import { ThriftAstMetadata } from '@cc/app/api/utils'; @Injectable({ providedIn: 'root' }) export class ThriftMetaLoader { diff --git a/src/app/api/thrift-instance-provider/types/api-metadata.ts b/src/app/api/thrift-instance-provider/types/api-metadata.ts index a4cd6b77..6f854bc2 100644 --- a/src/app/api/thrift-instance-provider/types/api-metadata.ts +++ b/src/app/api/thrift-instance-provider/types/api-metadata.ts @@ -1,4 +1,4 @@ -import { ThriftAstMetadata } from '../../../thrift-services'; +import { ThriftAstMetadata } from '@cc/app/api/utils'; export interface ApiMetadata { [name: string]: ThriftAstMetadata[]; diff --git a/src/app/api/thrift-instance-provider/types/provider-settings.ts b/src/app/api/thrift-instance-provider/types/provider-settings.ts index f5429857..63671893 100644 --- a/src/app/api/thrift-instance-provider/types/provider-settings.ts +++ b/src/app/api/thrift-instance-provider/types/provider-settings.ts @@ -1,6 +1,6 @@ import { ObservableInput } from 'rxjs'; -import { ThriftInstanceContext } from '../../../thrift-services'; +import { ThriftInstanceContext } from '@cc/app/api/utils'; export interface ProviderSettings { context: ThriftInstanceContext; diff --git a/src/app/api/utils/create-thrift-api/create-thrift-api.ts b/src/app/api/utils/create-thrift-api/create-thrift-api.ts new file mode 100644 index 00000000..4ffe1029 --- /dev/null +++ b/src/app/api/utils/create-thrift-api/create-thrift-api.ts @@ -0,0 +1,12 @@ +import { Observable } from 'rxjs'; + +import { ThriftApi } from './thrift-api'; +import { ThriftApiArgs } from './types/thrift-api-args'; + +export function createThriftApi() { + return (ThriftApi as unknown) as new (...args: ThriftApiArgs) => { + [N in keyof T]: ( + ...args: Parameters + ) => ReturnType extends Promise ? Observable : never; + }; +} diff --git a/src/app/api/utils/create-thrift-api/index.ts b/src/app/api/utils/create-thrift-api/index.ts new file mode 100644 index 00000000..c608f78c --- /dev/null +++ b/src/app/api/utils/create-thrift-api/index.ts @@ -0,0 +1 @@ +export * from './create-thrift-api'; diff --git a/src/app/api/utils/create-thrift-api/thrift-api.ts b/src/app/api/utils/create-thrift-api/thrift-api.ts new file mode 100644 index 00000000..9702f243 --- /dev/null +++ b/src/app/api/utils/create-thrift-api/thrift-api.ts @@ -0,0 +1,59 @@ +import { from } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; + +import { KeycloakTokenInfoService } from '@cc/app/shared/services'; + +import { ThriftConnector } from '../thrift-connector'; +import { createThriftInstance, thriftInstanceToObject } from '../thrift-instance'; +import { ThriftApiArgs } from './types/thrift-api-args'; + +export class ThriftApi extends ThriftConnector { + constructor(...[injector, options]: ThriftApiArgs) { + super( + injector.get(KeycloakTokenInfoService), + options.service, + options.endpoint, + options.deprecatedHeaders + ); + Object.assign( + this, + Object.fromEntries( + options.functions.map((methodName) => [ + methodName, + (...methodArgs) => + from(options.metadata()).pipe( + switchMap((metadata) => + this.callThriftServiceMethodWithConvert( + options.name, + options.serviceName, + methodName, + methodArgs, + metadata, + options.context + ) + ) + ), + ]) + ) + ); + } + + private callThriftServiceMethodWithConvert( + namespaceName: string, + serviceName: string, + methodName: string, + methodArgs: any[], + metadata: any, + context: any + ) { + const methodMetadata = metadata.find((m) => m.name === namespaceName).ast.service[ + serviceName + ].functions[methodName]; + const methodThriftArgs = methodArgs.map((arg, idx) => + createThriftInstance(metadata, context, namespaceName, methodMetadata.args[idx], arg) + ); + return this.callThriftServiceMethod(methodName, ...methodThriftArgs).pipe( + map((v) => thriftInstanceToObject(metadata, namespaceName, methodMetadata.type, v)) + ); + } +} diff --git a/src/app/api/utils/create-thrift-api/types/thrift-api-args.ts b/src/app/api/utils/create-thrift-api/types/thrift-api-args.ts new file mode 100644 index 00000000..96ea03c9 --- /dev/null +++ b/src/app/api/utils/create-thrift-api/types/thrift-api-args.ts @@ -0,0 +1,5 @@ +import { Injector } from '@angular/core'; + +import { ThriftApiOptions } from './thrift-api-options'; + +export type ThriftApiArgs = [Injector, ThriftApiOptions]; diff --git a/src/app/api/utils/create-thrift-api/types/thrift-api-options.ts b/src/app/api/utils/create-thrift-api/types/thrift-api-options.ts new file mode 100644 index 00000000..7049acc3 --- /dev/null +++ b/src/app/api/utils/create-thrift-api/types/thrift-api-options.ts @@ -0,0 +1,12 @@ +import { ThriftService } from '@cc/app/api/utils/thrift-connector/utils'; + +export interface ThriftApiOptions { + name: string; + service: ThriftService; + serviceName: string; + endpoint: string; + metadata: () => Promise; + context: any; + functions: string[]; + deprecatedHeaders?: boolean; +} diff --git a/src/app/api/utils/index.ts b/src/app/api/utils/index.ts new file mode 100644 index 00000000..2d6597d4 --- /dev/null +++ b/src/app/api/utils/index.ts @@ -0,0 +1,3 @@ +export * from './create-thrift-api'; +export * from './thrift-connector'; +export * from './thrift-instance'; diff --git a/src/app/api/thrift-connector/index.ts b/src/app/api/utils/thrift-connector/index.ts similarity index 100% rename from src/app/api/thrift-connector/index.ts rename to src/app/api/utils/thrift-connector/index.ts diff --git a/src/app/api/thrift-connector/thrift-connector.ts b/src/app/api/utils/thrift-connector/thrift-connector.ts similarity index 100% rename from src/app/api/thrift-connector/thrift-connector.ts rename to src/app/api/utils/thrift-connector/thrift-connector.ts diff --git a/src/app/api/thrift-connector/utils/connect-to-thrift-service.ts b/src/app/api/utils/thrift-connector/utils/connect-to-thrift-service.ts similarity index 100% rename from src/app/api/thrift-connector/utils/connect-to-thrift-service.ts rename to src/app/api/utils/thrift-connector/utils/connect-to-thrift-service.ts diff --git a/src/app/api/thrift-connector/utils/index.ts b/src/app/api/utils/thrift-connector/utils/index.ts similarity index 100% rename from src/app/api/thrift-connector/utils/index.ts rename to src/app/api/utils/thrift-connector/utils/index.ts diff --git a/src/app/api/thrift-connector/utils/prepare-thrift-service-method.ts b/src/app/api/utils/thrift-connector/utils/prepare-thrift-service-method.ts similarity index 100% rename from src/app/api/thrift-connector/utils/prepare-thrift-service-method.ts rename to src/app/api/utils/thrift-connector/utils/prepare-thrift-service-method.ts diff --git a/src/app/api/thrift-connector/utils/to-connect-options.ts b/src/app/api/utils/thrift-connector/utils/to-connect-options.ts similarity index 100% rename from src/app/api/thrift-connector/utils/to-connect-options.ts rename to src/app/api/utils/thrift-connector/utils/to-connect-options.ts diff --git a/src/app/api/thrift-connector/utils/types.ts b/src/app/api/utils/thrift-connector/utils/types.ts similarity index 100% rename from src/app/api/thrift-connector/utils/types.ts rename to src/app/api/utils/thrift-connector/utils/types.ts diff --git a/src/app/thrift-services/utils/thrift-instance/create-thrift-instance-utils.ts b/src/app/api/utils/thrift-instance/create-thrift-instance-utils.ts similarity index 100% rename from src/app/thrift-services/utils/thrift-instance/create-thrift-instance-utils.ts rename to src/app/api/utils/thrift-instance/create-thrift-instance-utils.ts diff --git a/src/app/thrift-services/utils/thrift-instance/create-thrift-instance.ts b/src/app/api/utils/thrift-instance/create-thrift-instance.ts similarity index 100% rename from src/app/thrift-services/utils/thrift-instance/create-thrift-instance.ts rename to src/app/api/utils/thrift-instance/create-thrift-instance.ts diff --git a/src/app/thrift-services/utils/thrift-instance/index.ts b/src/app/api/utils/thrift-instance/index.ts similarity index 100% rename from src/app/thrift-services/utils/thrift-instance/index.ts rename to src/app/api/utils/thrift-instance/index.ts diff --git a/src/app/thrift-services/utils/thrift-instance/namespace-type.ts b/src/app/api/utils/thrift-instance/namespace-type.ts similarity index 100% rename from src/app/thrift-services/utils/thrift-instance/namespace-type.ts rename to src/app/api/utils/thrift-instance/namespace-type.ts diff --git a/src/app/thrift-services/utils/thrift-instance/object-to-json.ts b/src/app/api/utils/thrift-instance/object-to-json.ts similarity index 100% rename from src/app/thrift-services/utils/thrift-instance/object-to-json.ts rename to src/app/api/utils/thrift-instance/object-to-json.ts diff --git a/src/app/thrift-services/utils/thrift-instance/thrift-instance-to-object.ts b/src/app/api/utils/thrift-instance/thrift-instance-to-object.ts similarity index 100% rename from src/app/thrift-services/utils/thrift-instance/thrift-instance-to-object.ts rename to src/app/api/utils/thrift-instance/thrift-instance-to-object.ts diff --git a/src/app/thrift-services/utils/thrift-instance/to-list-value-type.ts b/src/app/api/utils/thrift-instance/to-list-value-type.ts similarity index 100% rename from src/app/thrift-services/utils/thrift-instance/to-list-value-type.ts rename to src/app/api/utils/thrift-instance/to-list-value-type.ts diff --git a/src/app/thrift-services/utils/thrift-instance/types/index.ts b/src/app/api/utils/thrift-instance/types/index.ts similarity index 100% rename from src/app/thrift-services/utils/thrift-instance/types/index.ts rename to src/app/api/utils/thrift-instance/types/index.ts diff --git a/src/app/thrift-services/utils/thrift-instance/types/thrift-ast-metadata.ts b/src/app/api/utils/thrift-instance/types/thrift-ast-metadata.ts similarity index 100% rename from src/app/thrift-services/utils/thrift-instance/types/thrift-ast-metadata.ts rename to src/app/api/utils/thrift-instance/types/thrift-ast-metadata.ts diff --git a/src/app/thrift-services/utils/thrift-instance/types/thrift-namespace-context.ts b/src/app/api/utils/thrift-instance/types/thrift-namespace-context.ts similarity index 100% rename from src/app/thrift-services/utils/thrift-instance/types/thrift-namespace-context.ts rename to src/app/api/utils/thrift-instance/types/thrift-namespace-context.ts diff --git a/src/app/sections/payment-routing-rules/shop-payment-routing-ruleset/shop-payment-routing-ruleset.component.ts b/src/app/sections/payment-routing-rules/shop-payment-routing-ruleset/shop-payment-routing-ruleset.component.ts index 97392f3e..ca6167de 100644 --- a/src/app/sections/payment-routing-rules/shop-payment-routing-ruleset/shop-payment-routing-ruleset.component.ts +++ b/src/app/sections/payment-routing-rules/shop-payment-routing-ruleset/shop-payment-routing-ruleset.component.ts @@ -4,9 +4,11 @@ import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { combineLatest } from 'rxjs'; import { map, shareReplay, switchMap, take } from 'rxjs/operators'; +import { objectToJSON } from '@cc/app/api/utils'; + import { handleError } from '../../../../utils/operators/handle-error'; import { ErrorService } from '../../../shared/services/error'; -import { damselInstanceToObject, objectToJSON } from '../../../thrift-services'; +import { damselInstanceToObject } from '../../../thrift-services'; import { DomainCacheService } from '../../../thrift-services/damsel/domain-cache.service'; import { Predicate, TerminalObject } from '../../../thrift-services/damsel/gen-model/domain'; import { AddShopPaymentRoutingRuleDialogComponent } from './add-shop-payment-routing-rule-dialog'; diff --git a/src/app/sections/shop-details/shop-main-info/components/category/category.component.ts b/src/app/sections/shop-details/shop-main-info/components/category/category.component.ts index 2a95a526..8c68c004 100644 --- a/src/app/sections/shop-details/shop-main-info/components/category/category.component.ts +++ b/src/app/sections/shop-details/shop-main-info/components/category/category.component.ts @@ -15,7 +15,7 @@ export class CategoryComponent { @Input() set category(categoryID: number) { this.categoryID = categoryID; this.category$ = this.dominantCacheService - .getCategories() + .GetCategories() .pipe( map((categories) => categories.find((category) => category.ref === String(categoryID)) diff --git a/src/app/shared/components/party-modification-forms/contract/contract-template-ref/contract-template-ref.component.ts b/src/app/shared/components/party-modification-forms/contract/contract-template-ref/contract-template-ref.component.ts index 49d0447d..00e0807d 100644 --- a/src/app/shared/components/party-modification-forms/contract/contract-template-ref/contract-template-ref.component.ts +++ b/src/app/shared/components/party-modification-forms/contract/contract-template-ref/contract-template-ref.component.ts @@ -1,13 +1,13 @@ import { Component, Input, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MatSnackBar } from '@angular/material/snack-bar'; +import { ContractTemplate } from '@vality/dominant-cache-proto'; import isNil from 'lodash-es/isNil'; import sortBy from 'lodash-es/sortBy'; import { Observable } from 'rxjs'; import { map, tap } from 'rxjs/operators'; import { DominantCacheService } from '@cc/app/api/dominant-cache'; -import { ContractTemplate } from '@cc/app/api/dominant-cache/gen-model/dominant_cache'; import { ContractTemplateRef } from '../../../../../thrift-services/damsel/gen-model/domain'; @@ -42,7 +42,7 @@ export class ContractTemplateRefComponent implements OnInit { ) ); this.form.updateValueAndValidity(); - this.contracts$ = this.dominantCacheService.getContractTemplates().pipe( + this.contracts$ = this.dominantCacheService.GetContractTemplates().pipe( map((templates) => sortBy(templates, (o) => Number(o.ref))), tap( () => { diff --git a/src/app/shared/components/party-modification-forms/shop/category-ref/category-ref.component.ts b/src/app/shared/components/party-modification-forms/shop/category-ref/category-ref.component.ts index 86fc1660..2bbde97b 100644 --- a/src/app/shared/components/party-modification-forms/shop/category-ref/category-ref.component.ts +++ b/src/app/shared/components/party-modification-forms/shop/category-ref/category-ref.component.ts @@ -1,13 +1,13 @@ import { Component, Input, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MatSnackBar } from '@angular/material/snack-bar'; +import { Category } from '@vality/dominant-cache-proto'; import isNil from 'lodash-es/isNil'; import sortBy from 'lodash-es/sortBy'; import { Observable } from 'rxjs'; import { map, tap } from 'rxjs/operators'; import { DominantCacheService } from '@cc/app/api/dominant-cache'; -import { Category } from '@cc/app/api/dominant-cache/gen-model/dominant_cache'; import { CategoryRef } from '../../../../../thrift-services/damsel/gen-model/domain'; @@ -41,7 +41,7 @@ export class CategoryRefComponent implements OnInit { this.required ? Validators.required : null ) ); - this.categories$ = this.dominantCacheService.getCategories().pipe( + this.categories$ = this.dominantCacheService.GetCategories().pipe( map((categories) => sortBy(categories, (o) => Number(o.ref))), tap( () => { diff --git a/src/app/thrift-services/damsel/utils/create-damsel-instance.ts b/src/app/thrift-services/damsel/utils/create-damsel-instance.ts index 34202d5b..8b0801ef 100644 --- a/src/app/thrift-services/damsel/utils/create-damsel-instance.ts +++ b/src/app/thrift-services/damsel/utils/create-damsel-instance.ts @@ -1,5 +1,6 @@ +import { createThriftInstanceUtils } from '@cc/app/api/utils'; + import metadata from '../../../../assets/meta-damsel.json'; -import { createThriftInstanceUtils } from '../../utils/thrift-instance'; import * as base from '../gen-nodejs/base_types'; import * as claim_management from '../gen-nodejs/claim_management_types'; import * as domain_config from '../gen-nodejs/domain_config_types'; diff --git a/src/app/thrift-services/index.ts b/src/app/thrift-services/index.ts index 6caf7f50..dc7ee9b3 100644 --- a/src/app/thrift-services/index.ts +++ b/src/app/thrift-services/index.ts @@ -1,5 +1,4 @@ export * from './filters'; -export * from './utils/thrift-instance'; export * from './utils/get-thrift-instance'; export * from './file-storage'; export * from './messages'; diff --git a/thrift-config.json b/thrift-config.json index 76bb723e..7ca14ae4 100644 --- a/thrift-config.json +++ b/thrift-config.json @@ -35,16 +35,6 @@ "definitionFile": "domain_config.thrift" } ] - }, - { - "namespace": "dominant-cache", - "baseUrl": "./node_modules/dominant-cache-proto/proto", - "services": [ - { - "outputFolder": "dominant-cache", - "definitionFile": "dominant_cache.thrift" - } - ] } ] }