-
Notifications
You must be signed in to change notification settings - Fork 0
EPILIBS-186: wrap several endpoints with new adapters #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kailerg
wants to merge
1
commit into
master
Choose a base branch
from
rock-ai
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,79 @@ | ||
| import type { RoutingOptions } from '../utils/router'; | ||
|
|
||
| import { Router } from '../utils'; | ||
|
|
||
| export type Automata = 'ADD_USER_TO_ALL_GROUPS' | 'REMOVE_USER_FROM_ALL_GROUPS'; | ||
|
|
||
| export type AutomatonStatus = 'EXECUTING' | 'COMPLETED' | 'FAILED'; | ||
|
|
||
| export type AutomatonParameterType = 'string' | 'date' | 'long' | 'double'; | ||
|
|
||
| export interface AutomatonParameter { | ||
| objectType: AutomatonParameterType; | ||
| value: string | number | null; | ||
| } | ||
|
|
||
| export interface AutomatonParameters { | ||
| [key: string]: AutomatonParameter; | ||
| } | ||
|
|
||
| export interface AutomatedReadOutView { | ||
| jobId: number | null; | ||
| error: string | null; | ||
| status: AutomatonStatus | null; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Starts an automaton job for a given project. | ||
| * Base URL: POST `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/automaton/{AUTOMATA}` | ||
| * | ||
| * @example | ||
| * import { automatonAdapter } from 'epicenter-libs'; | ||
| * const job = await automatonAdapter.start('ADD_USER_TO_ALL_GROUPS', { | ||
| * userId: { objectType: 'string', value: 'user123' }, | ||
| * }); | ||
| * | ||
| * @param automata The automaton action to execute | ||
| * @param parameters Parameters for the automaton job, keyed by parameter name | ||
| * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist. | ||
| * @param [optionals.addNonce] If true, adds a nonce to the request | ||
| * @returns promise that resolves to the automaton job status | ||
| */ | ||
| export async function start( | ||
| automata: Automata, | ||
| parameters: AutomatonParameters, | ||
| optionals: { | ||
| addNonce?: boolean; | ||
| } & RoutingOptions = {}, | ||
| ): Promise<AutomatedReadOutView> { | ||
| const { addNonce, ...routingOptions } = optionals; | ||
| return await new Router() | ||
| .withSearchParams({ addNonce }) | ||
| .post(`/automaton/${automata}`, { | ||
| body: { parameters }, | ||
| ...routingOptions, | ||
| }).then(({ body }) => body); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Gets the status of an automaton job. | ||
| * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/automaton/{JOB_ID}` | ||
| * | ||
| * @example | ||
| * import { automatonAdapter } from 'epicenter-libs'; | ||
| * const status = await automatonAdapter.getStatus(12345); | ||
| * | ||
| * @param jobId The job ID returned from starting an automaton | ||
| * @param [optionals] Optional arguments; pass network call options overrides here. | ||
| * @returns promise that resolves to the automaton job status | ||
| */ | ||
| export async function getStatus( | ||
| jobId: number, | ||
| optionals: RoutingOptions = {}, | ||
| ): Promise<AutomatedReadOutView> { | ||
| return await new Router() | ||
| .get(`/automaton/${jobId}`, optionals) | ||
| .then(({ body }) => body); | ||
| } | ||
This file contains hidden or 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,117 @@ | ||
| import type { RoutingOptions } from '../utils/router'; | ||
| import type { ModelLanguage, Morphology } from '../utils/constants'; | ||
|
|
||
| import { Router } from '../utils'; | ||
|
|
||
| export interface StellaModelTool { | ||
| objectType: 'stella'; | ||
| gameMode?: boolean | null; | ||
| } | ||
|
|
||
| export interface VensimModelTool { | ||
| objectType: 'vensim'; | ||
| sensitivityMode?: boolean | null; | ||
| cinFiles?: unknown[] | null; | ||
| } | ||
|
|
||
| export type ModelTool = StellaModelTool | VensimModelTool; | ||
|
|
||
| export interface V1ExecutionContext { | ||
| version: unknown; | ||
| presets?: Record<string, object> | null; | ||
| mappedFiles?: Record<string, string> | null; | ||
| tool?: ModelTool; | ||
| } | ||
|
|
||
| export interface ModelContext { | ||
| [key: string]: unknown; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Gets the model context for a given model file. | ||
| * Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/context/{MODEL_FILE}` | ||
| * | ||
| * @example | ||
| * import { contextAdapter } from 'epicenter-libs'; | ||
| * const context = await contextAdapter.get('model.vmf'); | ||
| * | ||
| * @param modelFile The model file name | ||
| * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist. | ||
| * @param [optionals.morphology] The morphology type for the model context | ||
| * @returns promise that resolves to the model context | ||
| */ | ||
| export async function get( | ||
| modelFile: string, | ||
| optionals: { | ||
| morphology?: Morphology; | ||
| } & RoutingOptions = {}, | ||
| ): Promise<ModelContext> { | ||
| const { morphology, ...routingOptions } = optionals; | ||
| return await new Router() | ||
| .withSearchParams({ morphology }) | ||
| .get(`/context/${modelFile}`, routingOptions) | ||
| .then(({ body }) => body); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Upgrades the model context for a given model file. | ||
| * Base URL: POST `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/context/upgrade/{MODEL_FILE}` | ||
| * | ||
| * @example | ||
| * import { contextAdapter } from 'epicenter-libs'; | ||
| * await contextAdapter.upgrade('model.vmf', { morphology: 'SINGULAR' }); | ||
| * | ||
| * @param modelFile The model file name | ||
| * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist. | ||
| * @param [optionals.morphology] The morphology type for the upgrade | ||
| * @returns promise that resolves to void on success | ||
| */ | ||
| export async function upgrade( | ||
| modelFile: string, | ||
| optionals: { | ||
| morphology?: Morphology; | ||
| } & RoutingOptions = {}, | ||
| ): Promise<void> { | ||
| const { morphology, ...routingOptions } = optionals; | ||
| return await new Router() | ||
| .withSearchParams({ morphology }) | ||
| .post(`/context/upgrade/${modelFile}`, routingOptions) | ||
| .then(({ body }) => body); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Verifies a model context configuration. | ||
| * Base URL: POST `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/context/verify` | ||
| * | ||
| * @example | ||
| * import { contextAdapter } from 'epicenter-libs'; | ||
| * await contextAdapter.verify('model.vmf', { | ||
| * modelLanguage: 'VENSIM', | ||
| * morphology: 'SINGULAR', | ||
| * }); | ||
| * | ||
| * @param modelFile The model file name | ||
| * @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist. | ||
| * @param [optionals.morphology] The morphology type | ||
| * @param [optionals.modelLanguage] The model language | ||
| * @param [optionals.executionContext] The execution context configuration | ||
| * @returns promise that resolves to void on success | ||
| */ | ||
| export async function verify( | ||
| modelFile: string, | ||
| optionals: { | ||
| morphology?: Morphology; | ||
| modelLanguage?: ModelLanguage; | ||
| executionContext?: V1ExecutionContext; | ||
| } & RoutingOptions = {}, | ||
| ): Promise<void> { | ||
| const { morphology, modelLanguage, executionContext, ...routingOptions } = optionals; | ||
| return await new Router() | ||
| .post('/context/verify', { | ||
| body: { modelFile, morphology, modelLanguage, executionContext }, | ||
| ...routingOptions, | ||
| }).then(({ body }) => body); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using
awaitwith.then()is redundant. Anasyncfunction will automatically wrap the returned value in aPromise, so you can directly return the promise chain. This will make the code cleaner and slightly more performant.This comment applies to
getStatusin this file, and all similarasyncfunctions in the other new adapter files (context.ts,dashboard.ts, etc.).