-
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||
| } | ||
| 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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The model tool types (and V1ExecutionContext/ExecutionContext themselves) are already defined (and a bit more accurate to the Java definitions) in the
export interface StellaModelTool {
objectType: 'stella';
gameMode?: boolean;
}
export interface VensimModelTool {
objectType: 'vensim';
sensitivityMode?: boolean;
cinFiles?: string[];
}
export type ModelTool = StellaModelTool | VensimModelTool;
export interface V1ExecutionContext {
presets?: Record<string, Record<string, unknown>>;
mappedFiles?: Record<string, string>;
version: string; // optionally narrow to 'V1' to match the Java ExecutionContextVersion enum
tool?: ModelTool;
}
export interface ExecutionContext extends V1ExecutionContext {}
One thing to leave alone: the two |
||
| 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); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.