feat(plugin): WIP request api

pull/4705/head
charlie 2022-05-30 22:00:34 +08:00 committed by Tienson Qin
parent 0f62bc22e9
commit 2aa50f6199
3 changed files with 41 additions and 1 deletions

View File

@ -5,6 +5,8 @@ import { LSPluginCaller } from './LSPlugin.caller'
import { LSPluginExperiments } from './modules/LSPlugin.Experiments'
import { LSPluginFileStorage } from './modules/LSPlugin.Storage'
export type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
export type PluginLocalIdentity = string
export type ThemeMode = 'light' | 'dark'
@ -114,6 +116,23 @@ export type IDatom = [e: number, a: string, v: any, t: number, added: boolean]
export type IGitResult = { stdout: string; stderr: string; exitCode: number }
export type IRequestOptions<R = any> = {
url: string
headers: Record<string, string>
method: 'GET' | 'POST' | 'PUT' | 'DELETE'
data: any
timeout: number
dataType: 'json' | 'text' | 'base64' | 'arraybuffer'
success: (result: R) => void
fail: (err: any) => void
final: () => void
}
export type IRequestTask<R> = {
abort: () => void
promise: Promise<R>
}
export interface AppUserInfo {
[key: string]: any
}

View File

@ -1,4 +1,4 @@
import { LSPluginUser } from '../LSPlugin.user'
import { IRequestOptions, IRequestTask, LSPluginUser, WithOptional } from '../LSPlugin.user'
import { PluginLocal } from '../LSPlugin.core'
import { safeSnakeCase } from '../helpers'
@ -80,6 +80,19 @@ export class LSPluginExperiments {
)
}
request<R = any>(options: WithOptional<IRequestOptions<R>, keyof Omit<IRequestOptions, 'url'>>): IRequestTask<R> {
const pid = this.ctx.baseInfo.id
const reqID = this.invokeExperMethod('request', pid, options)
// TODO: impl
const task = {
abort: (() => reqID),
promise: Promise.resolve(null)
}
return task
}
ensureHostScope(): any {
if (window === top) {
throw new Error('Can not access host scope!')

View File

@ -808,6 +808,14 @@
(plugin-handler/register-extensions-enhancer
(keyword pid) type {:enhancer enhancer})))
(defn ^:export exper_request
[pid options]
nil)
(defn ^:export exper_abort_request
[req-id]
nil)
;; helpers
(defn ^:export query_element_by_id
[id]