Skip to content

Commit

Permalink
add id to Operation interface. (#779)
Browse files Browse the repository at this point in the history
* add id to Operation interface.
  • Loading branch information
b4rtaz authored Oct 27, 2022
1 parent 5b27ae8 commit 23b3a61
Show file tree
Hide file tree
Showing 20 changed files with 52 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface TestRequest {

const operation: Operation<TestRequest, unknown, unknown, unknown> = {
name: 'test',
id: 'test',
groupName: 'test',
method: 'POST',
urlPathParamNames: ['userId'],
Expand Down
1 change: 1 addition & 0 deletions packages/common/core/src/operations/Operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Core } from '../Core';

export interface Operation<Request, JSONRequest, Response, JSONResponse> {
name: string;
id: string;
groupName: string;
method: OperationRequestMethod;
urlPathPattern: string;
Expand Down
6 changes: 3 additions & 3 deletions packages/common/evmUtils/src/operations/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ describe('operations', () => {

for (const operation of operations) {
it(`${operation.name} defines all supported parameters`, () => {
const openApiPathParamNames = reader.readOperationPathParamNames(operation.name);
const openApiSearchParamNames = reader.readOperationSearchParamNames(operation.name)?.map(toCamel);
const openApiBodyParamNames = reader.readOperationRequestBodyParamNames(operation.name)?.map(toCamel);
const openApiPathParamNames = reader.readOperationPathParamNames(operation.id);
const openApiSearchParamNames = reader.readOperationSearchParamNames(operation.id)?.map(toCamel);
const openApiBodyParamNames = reader.readOperationRequestBodyParamNames(operation.id)?.map(toCamel);

expect(operation.urlPathParamNames.sort().join(',')).toBe(openApiPathParamNames?.sort().join(','));
expect(operation.urlSearchParamNames?.sort().join(',')).toBe(openApiSearchParamNames?.sort().join(','));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MoralisCore from '@moralisweb3/core';
import MoralisCore from '@moralisweb3/common-core';
import { EvmAddress, EvmChain } from '../../dataTypes';
import { getWalletTokenTransfersOperation, GetWalletTokenTransfersRequest } from './getWalletTokenTransfersOperation';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Erc20Transfer, EvmAddress, EvmAddressish, EvmChain, EvmChainish } from
import { EvmChainResolver } from '../../EvmChainResolver';
import { operations } from '../openapi';

type OperationName = 'getWalletTokenTransfers';
type PathParams = operations[OperationName]['parameters']['path'];
type QueryParams = operations[OperationName]['parameters']['query'];
type SuccessResponse = operations[OperationName]['responses']['200']['content']['application/json'];
type OperationId = 'getWalletTokenTransfers';
type PathParams = operations[OperationId]['parameters']['path'];
type QueryParams = operations[OperationId]['parameters']['query'];
type SuccessResponse = operations[OperationId]['responses']['200']['content']['application/json'];

// Exports

Expand All @@ -29,6 +29,7 @@ export const getWalletTokenTransfersOperation: PaginatedOperation<
> = {
method: 'GET',
name: 'getWalletTokenTransfers',
id: 'getWalletTokenTransfers',
groupName: 'token',
urlPathParamNames: ['address'],
urlSearchParamNames: ['chain', 'cursor', 'fromBlock', 'fromDate', 'limit', 'subdomain', 'toBlock', 'toDate'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MoralisCore from '@moralisweb3/core';
import MoralisCore from '@moralisweb3/common-core';
import { EvmAddress, EvmChain } from '../../dataTypes';
import { runContractFunctionOperation, RunContractFunctionRequest } from './runContractFunctionOperation';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { EvmAddress, EvmAddressish, EvmChain, EvmChainish } from '../../dataType
import { EvmChainResolver } from '../../EvmChainResolver';
import { operations } from '../openapi';

type OperationName = 'runContractFunction';
type PathParams = operations[OperationName]['parameters']['path'];
type QueryParams = operations[OperationName]['parameters']['query'];
type BodyParams = operations[OperationName]['requestBody']['content']['application/json'];
type OperationId = 'runContractFunction';
type PathParams = operations[OperationId]['parameters']['path'];
type QueryParams = operations[OperationId]['parameters']['query'];
type BodyParams = operations[OperationId]['requestBody']['content']['application/json'];
type RequestParams = PathParams & QueryParams & BodyParams;
type SuccessResponse = operations[OperationName]['responses']['200']['content']['application/json'];
type SuccessResponse = operations[OperationId]['responses']['200']['content']['application/json'];

// Exports

Expand All @@ -32,6 +32,7 @@ export const runContractFunctionOperation: Operation<
> = {
method: 'POST',
name: 'runContractFunction',
id: 'runContractFunction',
groupName: 'token',
urlPathParamNames: ['address'],
urlSearchParamNames: ['chain', 'functionName', 'providerUrl', 'subdomain'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MoralisCore from '@moralisweb3/core';
import MoralisCore from '@moralisweb3/common-core';
import { SolAddress, SolNetwork } from '../../dataTypes';
import { getBalanceOperation, GetBalanceRequest } from './getBalanceOperation';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { SolAddress, SolAddressish, SolNative, SolNetwork, SolNetworkish } from
import { SolNetworkResolver } from '../../SolNetworkResolver';
import { operations } from '../openapi';

type OperationName = 'balance';
type PathParams = operations[OperationName]['parameters']['path'];
type SuccessResponse = operations[OperationName]['responses']['200']['content']['application/json'];
type OperationId = 'balance';
type PathParams = operations[OperationId]['parameters']['path'];
type SuccessResponse = operations[OperationId]['responses']['200']['content']['application/json'];

// Exports

Expand All @@ -27,7 +27,8 @@ export const getBalanceOperation: Operation<
GetBalanceJSONResponse
> = {
method: 'GET',
name: 'balance',
name: 'getBalance',
id: 'balance',
groupName: 'account',
urlPathParamNames: ['network', 'address'],
urlPathPattern: '/account/{network}/{address}/balance',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MoralisCore from '@moralisweb3/core';
import MoralisCore from '@moralisweb3/common-core';
import { SolAddress, SolNetwork } from '../../dataTypes';
import { getNFTsOperation, GetNFTsRequest } from './getNFTsOperation';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { SolAddress, SolAddressish, SolNetwork, SolNetworkish } from '../../data
import { SolNetworkResolver } from '../../SolNetworkResolver';
import { operations } from '../openapi';

type OperationName = 'getNFTs';
type PathParams = operations[OperationName]['parameters']['path'];
type SuccessResponse = operations[OperationName]['responses']['200']['content']['application/json'];
type OperationId = 'getNFTs';
type PathParams = operations[OperationId]['parameters']['path'];
type SuccessResponse = operations[OperationId]['responses']['200']['content']['application/json'];

// Exports

Expand All @@ -23,6 +23,7 @@ export type GetNFTsResponse = ReturnType<typeof deserializeResponse>;
export const getNFTsOperation: Operation<GetNFTsRequest, GetNFTsJSONRequest, GetNFTsResponse, GetNFTsJSONResponse> = {
method: 'GET',
name: 'getNFTs',
id: 'getNFTs',
groupName: 'account',
urlPathParamNames: ['network', 'address'],
urlPathPattern: '/account/{network}/{address}/nft',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MoralisCore from '@moralisweb3/core';
import MoralisCore from '@moralisweb3/common-core';
import { SolAddress, SolNetwork } from '../../dataTypes';
import { getPortfolioOperation, GetPortfolioRequest } from './getPortfolioOperation';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { SolAddress, SolAddressish, SolNative, SolNetwork, SolNetworkish } from
import { SolNetworkResolver } from '../../SolNetworkResolver';
import { operations } from '../openapi';

type OperationName = 'getPortfolio';
type PathParams = operations[OperationName]['parameters']['path'];
type SuccessResponse = operations[OperationName]['responses']['200']['content']['application/json'];
type OperationId = 'getPortfolio';
type PathParams = operations[OperationId]['parameters']['path'];
type SuccessResponse = operations[OperationId]['responses']['200']['content']['application/json'];

// Exports

Expand All @@ -28,6 +28,7 @@ export const getPortfolioOperation: Operation<
> = {
method: 'GET',
name: 'getPortfolio',
id: 'getPortfolio',
groupName: 'account',
urlPathParamNames: ['network', 'address'],
urlPathPattern: '/account/{network}/{address}/portfolio',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MoralisCore from '@moralisweb3/core';
import MoralisCore from '@moralisweb3/common-core';
import { SolAddress, SolNetwork } from '../../dataTypes';
import { getSPLOperation, GetSPLRequest } from './getSPLOperation';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { SolAddress, SolAddressish, SolNative, SolNetwork, SolNetworkish } from
import { SolNetworkResolver } from '../../SolNetworkResolver';
import { operations } from '../openapi';

type OperationName = 'getSPL';
type PathParams = operations[OperationName]['parameters']['path'];
type SuccessResponse = operations[OperationName]['responses']['200']['content']['application/json'];
type OperationId = 'getSPL';
type PathParams = operations[OperationId]['parameters']['path'];
type SuccessResponse = operations[OperationId]['responses']['200']['content']['application/json'];

// Exports

Expand All @@ -23,6 +23,7 @@ export type GetSPLResponse = ReturnType<typeof deserializeResponse>;
export const getSPLOperation: Operation<GetSPLRequest, GetSPLJSONRequest, GetSPLResponse, GetSPLJSONResponse> = {
method: 'GET',
name: 'getSPL',
id: 'getSPL',
groupName: 'account',
urlPathParamNames: ['network', 'address'],
urlPathPattern: '/account/{network}/{address}/tokens',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MoralisCore from '@moralisweb3/core';
import MoralisCore from '@moralisweb3/common-core';
import { SolAddress, SolNetwork } from '../../dataTypes';
import { getNFTMetadataOperation, GetNFTMetadataRequest } from './getNFTMetadataOperation';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { SolAddress, SolAddressish, SolNetwork, SolNetworkish } from '../../data
import { SolNetworkResolver } from '../../SolNetworkResolver';
import { operations } from '../openapi';

type OperationName = 'getNFTMetadata';
type PathParams = operations[OperationName]['parameters']['path'];
type SuccessResponse = operations[OperationName]['responses']['200']['content']['application/json'];
type OperationId = 'getNFTMetadata';
type PathParams = operations[OperationId]['parameters']['path'];
type SuccessResponse = operations[OperationId]['responses']['200']['content']['application/json'];

// Exports

Expand All @@ -28,6 +28,7 @@ export const getNFTMetadataOperation: Operation<
> = {
method: 'GET',
name: 'getNFTMetadata',
id: 'getNFTMetadata',
groupName: 'nft',
urlPathParamNames: ['network', 'address'],
urlPathPattern: '/nft/{network}/{address}/metadata',
Expand Down
6 changes: 3 additions & 3 deletions packages/common/solUtils/src/operations/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ describe('operations', () => {

for (const operation of operations) {
it(`${operation.name} defines all supported parameters`, () => {
const openApiPathParamNames = reader.readOperationPathParamNames(operation.name);
const openApiSearchParamNames = reader.readOperationSearchParamNames(operation.name);
const openApiBodyParamNames = reader.readOperationRequestBodyParamNames(operation.name);
const openApiPathParamNames = reader.readOperationPathParamNames(operation.id);
const openApiSearchParamNames = reader.readOperationSearchParamNames(operation.id);
const openApiBodyParamNames = reader.readOperationRequestBodyParamNames(operation.id);

expect(operation.urlPathParamNames.sort().join(',')).toBe(openApiPathParamNames?.sort().join(','));
expect(operation.urlSearchParamNames?.sort().join(',')).toBe(openApiSearchParamNames?.sort().join(','));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MoralisCore from '@moralisweb3/core';
import MoralisCore from '@moralisweb3/common-core';
import { SolAddress, SolNetwork } from '../../dataTypes';
import { getTokenPriceOperation, GetTokenPriceRequest } from './getTokenPriceOperation';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { SolAddress, SolAddressish, SolNative, SolNetwork, SolNetworkish } from
import { SolNetworkResolver } from '../../SolNetworkResolver';
import { operations } from '../openapi';

type OperationName = 'getTokenPrice';
type PathParams = operations[OperationName]['parameters']['path'];
type SuccessResponse = operations[OperationName]['responses']['200']['content']['application/json'];
type OperationId = 'getTokenPrice';
type PathParams = operations[OperationId]['parameters']['path'];
type SuccessResponse = operations[OperationId]['responses']['200']['content']['application/json'];

// Exports

Expand All @@ -28,6 +28,7 @@ export const getTokenPriceOperation: Operation<
> = {
method: 'GET',
name: 'getTokenPrice',
id: 'getTokenPrice',
groupName: 'token',
urlPathParamNames: ['network', 'address'],
urlPathPattern: '/token/{network}/{address}/price',
Expand Down

1 comment on commit 23b3a61

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 60%
60.45% (295/488) 44.62% (54/121) 64.48% (69/107)
auth Coverage: 100%
100% (143/143) 90.9% (20/22) 100% (42/42)
evm-api Coverage: 82%
81.46% (466/572) 16.56% (54/326) 64.3% (191/297)
common-evm-utils Coverage: 63%
63.61% (675/1061) 35.35% (105/297) 31.79% (117/368)
sol-api Coverage: 100%
100% (20/20) 66.66% (4/6) 100% (6/6)
common-sol-utils Coverage: 75%
74.86% (134/179) 63.15% (12/19) 65.67% (44/67)
common-streams-utils Coverage: 95%
95.6% (674/705) 97.93% (190/194) 100% (244/244)
streams Coverage: 82%
82.72% (388/469) 64% (64/100) 73.6% (92/125)

Please sign in to comment.