import { InputSentenceProps } from "../../language/types.ts"; import "../../util/array.ts"; import { DeepPartial } from "../../util/types.ts"; import Core from "../api.ts"; import { ConnectionProps, ConnectionPropsDefault } from "./props.ts"; import { CoreRequest, CoreRequestParseSentence, CoreResponseParseSentence } from "./types.ts"; /** * @summary HTTP Core client * * Connects to an instance of RemoteCoreServer to call Core methods. Handles * (de)serialization automatically. */ export default class RemoteCoreClient implements Core { private props: ConnectionProps; ready: Promise = Promise.resolve(); constructor(options?: ConnectionProps) { this.props = { ...ConnectionPropsDefault, ...options }; } private async request(details: CoreRequest) { var response = await fetch(`http://${this.props.host}:${this.props.port}`, { method: "POST", headers: { "Accept": "application/json", "Content-Type": "application/json", }, body: JSON.stringify(details), }); return response.json(); } async parseSentence(input: string, options?: DeepPartial) { var request: CoreRequestParseSentence = { command: "parseSentence", options: { input, options, }, }; var { response } = await this.request(request) as CoreResponseParseSentence; return response; } }