Skip to content

Commit

Permalink
fix: repaired parse-server-migration. (#1138)
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz authored May 30, 2023
1 parent a9fdff2 commit 45fcd84
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .changeset/few-humans-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@moralisweb3/common-evm-utils': patch
'@moralisweb3/common-sol-utils': patch
---

The package includes now the `operationsV2All` collection for the backward compatibility. This collection will be deleted in the future.
4 changes: 2 additions & 2 deletions demos/express-proxy/src/api/proxyGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Moralis from 'moralis';
import { operationsV2 as solOperations } from 'moralis/common-sol-utils';
import { operationsV2 as evmOperations } from 'moralis/common-evm-utils';
import { operationsV2All as solOperations } from 'moralis/common-sol-utils';
import { operationsV2All as evmOperations } from 'moralis/common-evm-utils';
import express from 'express';
import axios from 'axios';
import { errorHandler } from '../middlewares/errorHandler';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { toCamel } from '@moralisweb3/common-core';
import { Endpoint } from '../types/Endpoint';
import fs from 'fs';

Expand Down Expand Up @@ -28,16 +29,15 @@ const getModulePackageName = (module: Module) => {
const generateCloudCode = (module: Module, endpoint: Endpoint) => {
let code = '';
const name = `${getModulePrefix(module)}${endpoint.name}`;
const groupName = toCamel(endpoint.group.replace(/\s+/, '_'));
const varName = `${endpoint.name}Operation`;
code += `
const ${varName} = getOperation('${endpoint.methodName}');
Parse.Cloud.define("${name}", async ({params, user, ip}: any) => {
try {
await beforeApiRequest(user, ip, '${endpoint.name}');
const request = upgradeRequest(params, ${varName});
const result = await Moralis.${module}.${endpoint.group}.${endpoint.methodName}(${
endpoint.noArgs ? '' : 'request'
});
const result = await Moralis.${module}.${groupName}.${endpoint.methodName}(${endpoint.noArgs ? '' : 'request'});
return result?.raw;
} catch (error) {
throw new Error(getErrorMessage(error, '${name}'));
Expand All @@ -57,7 +57,7 @@ import { MoralisError, Operation } from '@moralisweb3/common-core';
import { handleRateLimit } from '../../rateLimit';
import { upgradeRequest } from '../upgradeRequest'
import { AxiosError } from 'axios';
import { operations } from '${packageName}';
import { operationsV2All as operations } from '${packageName}';
declare const Parse: any;
function getErrorMessage(error: Error, name: string) {
Expand Down
2 changes: 1 addition & 1 deletion demos/parse-server-migration/src/cloud/generated/evmApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MoralisError, Operation } from '@moralisweb3/common-core';
import { handleRateLimit } from '../../rateLimit';
import { upgradeRequest } from '../upgradeRequest'
import { AxiosError } from 'axios';
import { operationsV2 as operations } from '@moralisweb3/common-evm-utils';
import { operationsV2All as operations } from '@moralisweb3/common-evm-utils';
declare const Parse: any;

function getErrorMessage(error: Error, name: string) {
Expand Down
2 changes: 1 addition & 1 deletion demos/parse-server-migration/src/cloud/generated/solApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MoralisError, Operation } from '@moralisweb3/common-core';
import { handleRateLimit } from '../../rateLimit';
import { upgradeRequest } from '../upgradeRequest'
import { AxiosError } from 'axios';
import { operationsV2 as operations } from '@moralisweb3/common-sol-utils';
import { operationsV2All as operations } from '@moralisweb3/common-sol-utils';
declare const Parse: any;

function getErrorMessage(error: Error, name: string) {
Expand Down
4 changes: 2 additions & 2 deletions demos/parse-server/src/api/proxyGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Moralis from 'moralis';
import express from 'express';
import axios from 'axios';
import { errorHandler } from '../middlewares/errorHandler';
import { operationsV2 as solOperations } from 'moralis/common-sol-utils';
import { operationsV2 as evmOperations } from 'moralis/common-evm-utils';
import { operationsV2All as solOperations } from 'moralis/common-sol-utils';
import { operationsV2All as evmOperations } from 'moralis/common-evm-utils';
import { convertOperationToDescriptor } from '@moralisweb3/api-utils';

const proxyRouter = express.Router();
Expand Down
15 changes: 14 additions & 1 deletion packages/common/evmUtils/src/operations/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getNFTMetadataOperation,
getNFTOwnersOperation,
getNFTTokenIdOwnersOperation,
getNFTTradesOperation,
getNFTTransfersByBlockOperation,
getNFTTransfersFromToBlockOperation,
getNFTTransfersOperation,
Expand All @@ -34,6 +35,7 @@ import {
getWalletTokenTransfersOperation,
getErc20ApprovalsOperation,
getErc20BurnsOperation,
getErc20TransfersOperation,
} from './token';
import {
getTransactionOperation,
Expand All @@ -42,7 +44,7 @@ import {
getWalletTransactionsVerboseOperation,
getInternalTransactionsOperation,
} from './transaction';
import { runContractFunctionOperation } from './utils';
import { endpointWeightsOperation, runContractFunctionOperation, web3ApiVersionOperation } from './utils';

export const operationsV2 = [
getBlockOperation,
Expand Down Expand Up @@ -91,3 +93,14 @@ export const operationsV2 = [
syncNFTContractOperation,
uploadFolderOperation,
];

/**
* @deprecated This list includes upgraded operations to the hybrid approach in the old format.
*/
export const operationsV2All = [
...operationsV2,
endpointWeightsOperation,
web3ApiVersionOperation,
getNFTTradesOperation,
getErc20TransfersOperation,
];
6 changes: 6 additions & 0 deletions packages/common/solUtils/src/operations/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getNFTsOperation } from './account/getNFTsOperation';
import { getPortfolioOperation } from './account/getPortfolioOperation';
import { getSPLOperation } from './account/getSPLOperation';
import { getNFTMetadataOperation } from './nft/getNFTMetadataOperation';
import { getTokenPriceOperation } from './token/getTokenPriceOperation';

export const operationsV2 = [
getBalanceOperation,
Expand All @@ -11,3 +12,8 @@ export const operationsV2 = [
getSPLOperation,
getNFTMetadataOperation,
];

/**
* @deprecated This list includes upgraded operations to the hybrid approach in the old format.
*/
export const operationsV2All = [...operationsV2, getTokenPriceOperation];
23 changes: 4 additions & 19 deletions packages/next/src/MoralisNextApi/Modules.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { EvmApi } from '@moralisweb3/evm-api';
import { Core, UnknownOperation } from '@moralisweb3/common-core';
import {
endpointWeightsOperation,
operationsV2 as evmOperationsV2,
getNFTTradesOperation,
web3ApiVersionOperation,
} from 'moralis/common-evm-utils';
import { getTokenPriceOperation, operationsV2 as solOperations } from 'moralis/common-sol-utils';
import { operationsV2All as evmOperationsV2 } from 'moralis/common-evm-utils';
import { operationsV2All as solOperationsV2 } from 'moralis/common-sol-utils';
import { operations as authOperations } from '@moralisweb3/common-auth-utils';
import { Auth } from '@moralisweb3/auth';
import { SolApi } from '@moralisweb3/sol-api';
Expand Down Expand Up @@ -47,19 +42,9 @@ export class Module {
}
}

const allEvmOperations = [
...evmOperationsV2,
// TODO: I've added these 3 operations manually here but this file should use a converter V2 -> V3.
endpointWeightsOperation,
web3ApiVersionOperation,
getNFTTradesOperation,
];

const allSolOperations = [...solOperations, getTokenPriceOperation];

const modules: Module[] = [
new Module(EvmApi.moduleName, allEvmOperations as UnknownOperation[]),
new Module(SolApi.moduleName, allSolOperations as UnknownOperation[]),
new Module(EvmApi.moduleName, evmOperationsV2 as UnknownOperation[]),
new Module(SolApi.moduleName, solOperationsV2 as UnknownOperation[]),
new Module(Auth.moduleName, authOperations as UnknownOperation[]),
];

Expand Down

1 comment on commit 45fcd84

@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: 20%
20.6% (61/296) 20.48% (17/83) 19.04% (12/63)
auth Coverage: 89%
92.45% (98/106) 83.33% (20/24) 86.66% (26/30)
evm-api Coverage: 96%
96.87% (93/96) 66.66% (6/9) 95.23% (60/63)
common-aptos-utils Coverage: 4%
4.56% (151/3306) 4.49% (25/556) 5.53% (45/813)
common-evm-utils Coverage: 65%
65.48% (1533/2341) 26.89% (256/952) 44.63% (416/932)
sol-api Coverage: 100%
100% (40/40) 66.66% (6/9) 100% (15/15)
common-sol-utils Coverage: 69%
69.04% (203/294) 51.42% (18/35) 55.67% (54/97)
common-streams-utils Coverage: 90%
90.73% (1204/1327) 73.63% (363/493) 82.07% (444/541)
streams Coverage: 88%
88.2% (576/653) 68.81% (64/93) 88.02% (125/142)

Please sign in to comment.