TD-237: New @vality/dominant-cache-proto API codegen (#53)

This commit is contained in:
Rinat Arsaev 2022-03-24 21:12:04 +03:00 committed by GitHub
parent a9c269bac4
commit 4fcc1cbde0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 178 additions and 218 deletions

View File

@ -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

View File

@ -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 }}

18
.github/workflows/main.yaml vendored Normal file
View File

@ -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 }}

View File

@ -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

View File

@ -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

23
package-lock.json generated
View File

@ -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",

View File

@ -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",

View File

@ -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<CodegenClient>() {
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,
});
}
}

View File

@ -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',
};
}
}

View File

@ -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<Category[]> {
return this.instanceProvider.methods$.pipe(
switchMap(({ toPlainObject }) =>
this.callThriftServiceMethod<Category[]>('GetCategories').pipe(
map((v) => toPlainObject(toListValueType('Category'), v))
)
)
);
}
getDocumentTypes(): Observable<DocumentType[]> {
return this.instanceProvider.methods$.pipe(
switchMap(({ toPlainObject }) =>
this.callThriftServiceMethod<DocumentType[]>('GetDocumentTypes').pipe(
map((v) => toPlainObject(toListValueType('DocumentType'), v))
)
)
);
}
getCashRegisterProviders(): Observable<CashRegisterProvider[]> {
return this.instanceProvider.methods$.pipe(
switchMap(({ toPlainObject }) =>
this.callThriftServiceMethod<CashRegisterProvider[]>(
'GetCashRegisterProviders'
).pipe(map((v) => toPlainObject(toListValueType('CashRegisterProvider'), v)))
)
);
}
getContractTemplates(): Observable<ContractTemplate[]> {
return this.instanceProvider.methods$.pipe(
switchMap(({ toPlainObject }) =>
this.callThriftServiceMethod<ContractTemplate[]>('GetContractTemplates').pipe(
map((v) => toPlainObject(toListValueType('ContractTemplate'), v))
)
)
);
}
getTradeBlocs(): Observable<TradeBloc[]> {
return this.instanceProvider.methods$.pipe(
switchMap(({ toPlainObject }) =>
this.callThriftServiceMethod<TradeBloc[]>('GetTradeBlocs').pipe(
map((v) => toPlainObject(toListValueType('TradeBloc'), v))
)
)
);
}
getCountries(): Observable<Country[]> {
return this.instanceProvider.methods$.pipe(
switchMap(({ toPlainObject }) =>
this.callThriftServiceMethod<Country[]>('GetCountries').pipe(
map((v) => toPlainObject(toListValueType('Country'), v))
)
)
);
}
}

View File

@ -1 +0,0 @@
export * from './dominant-cache.service';

View File

@ -1 +1 @@
export * from './dominant-cache';
export * from './dominant-cache.service';

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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 {

View File

@ -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';

View File

@ -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';

View File

@ -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 {

View File

@ -1,4 +1,4 @@
import { ThriftAstMetadata } from '../../../thrift-services';
import { ThriftAstMetadata } from '@cc/app/api/utils';
export interface ApiMetadata {
[name: string]: ThriftAstMetadata[];

View File

@ -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;

View File

@ -0,0 +1,12 @@
import { Observable } from 'rxjs';
import { ThriftApi } from './thrift-api';
import { ThriftApiArgs } from './types/thrift-api-args';
export function createThriftApi<T extends { [N in PropertyKey]: any }>() {
return (ThriftApi as unknown) as new (...args: ThriftApiArgs) => {
[N in keyof T]: (
...args: Parameters<T[N]>
) => ReturnType<T[N]> extends Promise<infer R> ? Observable<R> : never;
};
}

View File

@ -0,0 +1 @@
export * from './create-thrift-api';

View File

@ -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))
);
}
}

View File

@ -0,0 +1,5 @@
import { Injector } from '@angular/core';
import { ThriftApiOptions } from './thrift-api-options';
export type ThriftApiArgs = [Injector, ThriftApiOptions];

View File

@ -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<any>;
context: any;
functions: string[];
deprecatedHeaders?: boolean;
}

View File

@ -0,0 +1,3 @@
export * from './create-thrift-api';
export * from './thrift-connector';
export * from './thrift-instance';

View File

@ -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';

View File

@ -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))

View File

@ -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(
() => {

View File

@ -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(
() => {

View File

@ -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';

View File

@ -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';

View File

@ -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"
}
]
}
]
}