-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor service wizard, add narrative service.
- Loading branch information
1 parent
5f69af7
commit 3866202
Showing
9 changed files
with
142 additions
and
89 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,33 @@ | ||
/* narrativeService */ | ||
import { dynamicService } from './serviceWizardApi'; | ||
import { baseApi } from './index'; | ||
|
||
const narrativeService = dynamicService({ | ||
name: 'NarrativeService', | ||
release: 'release', | ||
}); | ||
|
||
export interface NarrativeServiceParams { | ||
getStatus: void; | ||
} | ||
|
||
interface NarrativeServiceResults { | ||
getStatus: unknown; | ||
} | ||
|
||
export const narrativeServiceApi = baseApi.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
getStatus: builder.query< | ||
NarrativeServiceResults['getStatus'], | ||
NarrativeServiceParams['getStatus'] | ||
>({ | ||
query: () => | ||
narrativeService({ | ||
method: 'NarrativeService.status', | ||
params: [], | ||
}), | ||
}), | ||
}), | ||
}); | ||
|
||
export const { getStatus } = narrativeServiceApi.endpoints; |
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,67 @@ | ||
/* api/utils/common */ | ||
import { FetchBaseQueryError } from '@reduxjs/toolkit/query/react'; | ||
/* | ||
JSONRPC Specification details | ||
JSON-RPC 1.0 - https://www.jsonrpc.org/specification_v1 | ||
JSON-RPC 1.1 wd - https://jsonrpc.org/historical/json-rpc-1-1-wd.html | ||
JSON-RPC 2.0 - https://www.jsonrpc.org/specification | ||
- id | ||
- 2.0 allows id to be string, number (with no fractional part) or null | ||
- 1.1 allows id to be "any JSON type" | ||
- version | ||
- a string in both JSONRPC 1.1 and 2.0. | ||
*/ | ||
// KBase mostly uses strings, or string serializable values, so we can too. | ||
type JsonRpcError = { | ||
version: '1.1'; | ||
id: string; | ||
error: { | ||
name: string; | ||
code: number; | ||
message: string; | ||
}; | ||
}; | ||
|
||
export type KBaseBaseQueryError = | ||
| FetchBaseQueryError | ||
| { | ||
status: 'JSONRPC_ERROR'; | ||
data: JsonRpcError; | ||
}; | ||
|
||
export const isJsonRpcError = (obj: unknown): obj is JsonRpcError => { | ||
if ( | ||
typeof obj === 'object' && | ||
obj !== null && | ||
['version', 'error', 'id'].every((k) => k in obj) | ||
) { | ||
const { version, error } = obj as { version: string; error: unknown }; | ||
const versionsSupported = new Set(['1.1', '2.0']); | ||
if (!versionsSupported.has(version)) return false; | ||
if ( | ||
typeof error === 'object' && | ||
error !== null && | ||
['name', 'code', 'message'].every((k) => k in error) | ||
) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
/** | ||
* Type predicate to narrow an unknown error to `FetchBaseQueryError` | ||
*/ | ||
export function isFetchBaseQueryError( | ||
error: unknown | ||
): error is FetchBaseQueryError { | ||
return typeof error === 'object' && error !== null && 'status' in error; | ||
} | ||
|
||
export const isKBaseBaseQueryError = ( | ||
error: unknown | ||
): error is KBaseBaseQueryError => { | ||
const fbq = isFetchBaseQueryError(error); | ||
const condition = fbq && isJsonRpcError(error.data); | ||
return condition; | ||
}; |
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
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