-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
91 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@moralisweb3/next': patch | ||
--- | ||
|
||
Fix issues related to several NextJS hooks, due to the serialisation of the request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { EvmApi } from '@moralisweb3/evm-api'; | ||
import { operations as evmOperations } from 'moralis/common-evm-utils'; | ||
import { operations as solOperations } from 'moralis/common-sol-utils'; | ||
import { Operation } from 'moralis/common-core'; | ||
import { operations as authOperations } from '@moralisweb3/common-auth-utils'; | ||
import { Auth } from '@moralisweb3/auth'; | ||
import { SolApi } from '@moralisweb3/sol-api'; | ||
import Moralis from 'moralis'; | ||
|
||
export type UnknownOperation = Operation<unknown, unknown, unknown, unknown>; | ||
|
||
export class Module { | ||
public name: string; | ||
public baseUrl: string; | ||
public operations: UnknownOperation[]; | ||
|
||
constructor({ name, baseUrl, operations }: { name: string; baseUrl: string; operations: UnknownOperation[] }) { | ||
this.name = name; | ||
this.baseUrl = baseUrl; | ||
this.operations = operations; | ||
} | ||
|
||
getOperationByName(operationName: string) { | ||
const operation = this.operations.find((op) => op.name === operationName); | ||
|
||
if (!operation) { | ||
throw new Error(`Operation ${operationName} not found`); | ||
} | ||
|
||
return operation; | ||
} | ||
} | ||
|
||
const modules: Module[] = [ | ||
new Module({ | ||
name: EvmApi.moduleName, | ||
baseUrl: Moralis.EvmApi.baseUrl, | ||
operations: evmOperations as UnknownOperation[], | ||
}), | ||
new Module({ | ||
name: SolApi.moduleName, | ||
baseUrl: Moralis.SolApi.baseUrl, | ||
operations: solOperations as UnknownOperation[], | ||
}), | ||
new Module({ | ||
name: Auth.moduleName, | ||
baseUrl: Moralis.Auth.baseUrl, | ||
operations: authOperations as UnknownOperation[], | ||
}), | ||
]; | ||
|
||
export function getModuleByName(moduleName: string) { | ||
const module = modules.find((mod) => mod.name === moduleName); | ||
|
||
if (!module) { | ||
throw new Error(`Module ${moduleName} not found`); | ||
} | ||
|
||
return module; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 3 additions & 44 deletions
47
packages/next/src/MoralisNextApi/RequestHandlerResolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,10 @@ | ||
import { EvmApi } from '@moralisweb3/evm-api'; | ||
import { operations as evmOperations } from 'moralis/common-evm-utils'; | ||
import { operations as solOperations } from 'moralis/common-sol-utils'; | ||
import { Operation } from 'moralis/common-core'; | ||
import { OperationResolver } from '@moralisweb3/api-utils'; | ||
import { operations as authOperations } from '@moralisweb3/common-auth-utils'; | ||
import { Auth } from '@moralisweb3/auth'; | ||
import { SolApi } from '@moralisweb3/sol-api'; | ||
import Moralis from 'moralis'; | ||
|
||
type UnknownOperation = Operation<unknown, unknown, unknown, unknown>; | ||
|
||
interface Module { | ||
name: string; | ||
baseUrl: string; | ||
operations: UnknownOperation[]; | ||
} | ||
|
||
const modules: Module[] = [ | ||
{ | ||
name: EvmApi.moduleName, | ||
baseUrl: Moralis.EvmApi.baseUrl, | ||
operations: evmOperations as UnknownOperation[], | ||
}, | ||
{ | ||
name: SolApi.moduleName, | ||
baseUrl: Moralis.SolApi.baseUrl, | ||
operations: solOperations as UnknownOperation[], | ||
}, | ||
{ | ||
name: Auth.moduleName, | ||
baseUrl: Moralis.Auth.baseUrl, | ||
operations: authOperations as UnknownOperation[], | ||
}, | ||
]; | ||
import { Module, UnknownOperation } from './Modules'; | ||
|
||
export class RequestHandlerResolver { | ||
public static tryResolve(moduleName: string, operationName: string) { | ||
const module = modules.find((mod) => mod.name === moduleName); | ||
if (!module) { | ||
return null; | ||
} | ||
|
||
const operation = module.operations.find((op) => op.name === operationName); | ||
if (!operation) { | ||
return null; | ||
} | ||
|
||
public static tryResolve(module: Module, operation: UnknownOperation) { | ||
// TODO: use nullable/pagianted resolver here | ||
return new OperationResolver(operation, module.baseUrl, Moralis.Core); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters