-
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.
Merge pull request #953 from MoralisWeb3/fix/serialisation-nextjs-req…
…uests fix: serialisation nextjs requests
- Loading branch information
Showing
13 changed files
with
113 additions
and
70 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 requests that can return null response |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NullableOperationResolver } from './NullableOperationResolver'; | ||
import { OperationResolver } from './OperationResolver'; | ||
import { PaginatedOperationResolver } from './PaginatedOperationResolver'; | ||
|
||
export type UnknownNullableOperationResolver = NullableOperationResolver<unknown, unknown, unknown, unknown>; | ||
export type UnknownPaginatedOperationResolver = PaginatedOperationResolver<any, unknown, unknown, unknown>; | ||
export type UnknownDefaultOperationResolver = OperationResolver<unknown, unknown, unknown, unknown>; | ||
|
||
export type UnknownOperationResolver = | ||
| UnknownNullableOperationResolver | ||
| UnknownPaginatedOperationResolver | ||
| UnknownDefaultOperationResolver; |
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,6 +1,5 @@ | ||
import { Operation } from '@moralisweb3/common-core'; | ||
import { UnknownOperation } from '@moralisweb3/common-core'; | ||
|
||
export type UnknownOperation = Operation<unknown, unknown, unknown, unknown>; | ||
export type OperationAction = Pick<UnknownOperation, 'name' | 'groupName' | 'method' | 'id' | 'urlSearchParamNames'>; | ||
|
||
export type Module = 'evmApi' | 'solApi' | 'auth'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { EvmApi } from '@moralisweb3/evm-api'; | ||
import Core, { UnknownOperation } from '@moralisweb3/common-core'; | ||
import { operations as evmOperations } from 'moralis/common-evm-utils'; | ||
import { operations as solOperations } 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'; | ||
import { UnknownOperationResolver } from '@moralisweb3/api-utils'; | ||
|
||
export class Module { | ||
constructor(public readonly moduleName: string, public readonly operations: UnknownOperation[]) {} | ||
|
||
getOperationByName(operationName: string) { | ||
const operation = this.operations.find((op) => op.name === operationName); | ||
|
||
if (!operation) { | ||
throw new Error(`Operation ${operationName} not found`); | ||
} | ||
|
||
return operation; | ||
} | ||
|
||
getRequestHandler(operation: UnknownOperation, core: Core) { | ||
const apiModule = core.getModule(this.moduleName) as unknown as Record< | ||
string, | ||
Record<string, UnknownOperationResolver['fetch']> | ||
>; | ||
|
||
const apiGroup = apiModule[operation.groupName]; | ||
|
||
if (!apiGroup) { | ||
throw new Error(`Operation ${operation.name} has no group name in ${this.moduleName}`); | ||
} | ||
|
||
const requestHandler = apiGroup[operation.name]; | ||
|
||
if (!requestHandler) { | ||
throw new Error(`Operation ${operation.name} has no requestHandler in ${this.moduleName}.${apiGroup}`); | ||
} | ||
|
||
return requestHandler; | ||
} | ||
} | ||
|
||
const modules: Module[] = [ | ||
new Module(EvmApi.moduleName, evmOperations as UnknownOperation[]), | ||
new Module(SolApi.moduleName, solOperations as UnknownOperation[]), | ||
new Module(Auth.moduleName, authOperations as UnknownOperation[]), | ||
]; | ||
|
||
export function getModuleByName(moduleName: string) { | ||
const module = modules.find((currentModule) => currentModule.moduleName === 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
51 changes: 0 additions & 51 deletions
51
packages/next/src/MoralisNextApi/RequestHandlerResolver.ts
This file was deleted.
Oops, something went wrong.
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
e00f50f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test coverage